CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name3 data_type,
....
)
Example:
<?php
$con = mysql_connect("localhost","root","123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$sql = "CREATE TABLE tblname
(
id int(11),
Name varchar(15),
Sex varchar(15),
)";
mysql_query($sql,$con);
mysql_close($con);
?>
more...
Create Connected with Database
<?php
$con = mysql_connect("localhost","root","123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
?>
INSERT INTO Table a Database Tale
<form action="CreateAdd.php" method="post">
</form>
//CreateAdd.php
<?php
require("db_connect.inc");
$sql="INSERT INTO tblname(id,name,sex)
VALUES('$_POST[id]','$_POST[name]','$_POST[sex]')";
if(!mysql_query($sql,$con)){
die("Error:".mysql_error());
}
echo "1 Record Added";
mysql_close($con);
?>
Create View Data from Database
//view_data.php
<?php
require("db_connect.inc");
$rs=mysql_query("Select * from tblname") or die(mysql_error());
?>
<html>
<body>
<center>
<h3>Show List of Student</h3>
<table border="1" width="388">
<tr align="center">
<th width="70"> ID </th>
<th width="208"> Name </th>
<th width="88"> Sex </th>
</tr>
<?php
while($row=mysql_fetch_array($rs))
{
?>
<tr align="center">
<td><?echo $row['id']?></td>
<td><?echo $row['name']?></td>
<td><?echo $row['sex']?></td>
</tr>
<?php } ?>
</table>
</center>
</body>
</html>
