日期:2014-05-16 浏览次数:20896 次
<?php
$username = $_POST['username'];
$name = $_POST['name'];
$pwd = $_POST['pwd'];
$email = $_POST['email'];
if(!empty($username))
{
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);//连接一个名字叫test的数据库
$sql = "select * from t_user";
if(!$con)
{
die("Error:".mysql_error());
}
$result = mysql_query($sql);
echo "<table border ='1' bgcolor = 'lightblue'>";
echo "<tr><th>用户名</th><th>姓名</th><th>密码</th><th>邮箱</th></tr>";
while($row = mysql_fetch_array($result))//记得这里是把$result放入 mysql_fetch_array中,我一开始吧$sql放进去也报的是上面这种错
{
echo "<tr><td>{$row['f_username']}</td>";//这里字段名写错就可能导致出现上面的错误
echo "<td>{$row['f_name']}</td>";
echo "<td>{$row['f_password']}</td>";
echo "<td>{$row['f_email']}</td></tr>\n";
}
echo "</table>";
mysql_close($con);//关闭连接
}
?>