insert数据,显示数据列表

<!--向表中添加数据,并且显示出来-->

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db", $con); //选取数据库

//////////////////////////////////向表内插入数据
mysql_query("INSERT INTO world (Id, Name, Location)
VALUES ('
$_POST[Id]', '$_POST[Name]', '$_POST[Location]')");

/////////////////////////////////查询出数据,显示出来
$result = mysql_query("SELECT * FROM world");
echo "<table border='1'>
<tr>
<th>id</th>
<th>name</th>
<th>location</th>
</tr>
";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Id'] . "</td>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['Location'] . "</td>";
echo "</tr>";
}
echo "</table>";

/////////////////////////////////关闭连接
mysql_close($con);
?>

 

posted on 2010-09-18 00:07  lovening  阅读(167)  评论(0编辑  收藏  举报