`
java_xiaoyi
  • 浏览: 46788 次
  • 性别: Icon_minigender_1
  • 来自: 木木乃州
社区版块
存档分类
最新评论

mysql_fetch_array(): supplied argument is not a valid MySQL result resource....

    博客分类:
  • PHP
阅读更多
还是结合代码说明一下:
<?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);//关闭连接
}
?>

呵呵,每天积累一点东西。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics