1. Simple code to Create Table
NB: Make sure that the usename root , pasword root and database name SNIT can change across different machines.
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("SNIT",$con);
$sql="Select * from student";
$data=mysql_query($sql,$con);
echo "<table border=1 align=center width=50%>";
echo "<tr><th>Name</th><th>Roll No</th><th>Marks</th></tr>";
while($row=mysql_fetch_array($data))
{
$name=$row['name'];
$rollno=$row['rollno'];
$marks=$row['marks'];
echo "<tr><td>$name</td><td>$rollno</td><td>$marks</td></tr>";
}
mysql_close($con);
?>
NB: Make sure that the usename root , pasword root and database name SNIT can change across different machines.
<?php
$con=mysql_connect("localhost","root","root");
mysql_select_db("SNIT",$con);
mysql_query("create table student(name TEXT(20),rollno int(3),marks int(3))");
?>
2. Simple code to Insert into the table
<?php
$con=mysql_connect("localhost","root","root");
mysql_select_db("SNIT",$con);
mysql_query("insert into student values('ARJUN',108,100)");
?>
$con=mysql_connect("localhost","root","root");
mysql_select_db("SNIT",$con);
mysql_query("insert into student values('ARJUN',108,100)");
?>
3. Simple code to View the content of the table
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("SNIT",$con);
$sql="Select * from student";
$data=mysql_query($sql,$con);
echo "<table border=1 align=center width=50%>";
echo "<tr><th>Name</th><th>Roll No</th><th>Marks</th></tr>";
while($row=mysql_fetch_array($data))
{
$name=$row['name'];
$rollno=$row['rollno'];
$marks=$row['marks'];
echo "<tr><td>$name</td><td>$rollno</td><td>$marks</td></tr>";
}
mysql_close($con);
?>
This comment has been removed by the author.
ReplyDelete