用户登陆问题

用户登陆问题

运行了会出提示:数据库执行失败:query was empty.高手帮帮看是哪里出问题了,感激中.

<?php
session_start();
require_once('connect.php');
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<?php
$username=$_POST['username'];
$password=$_POST['password'];
$checkcode=$_POST['checkcode'];
$sql="select id,username,password from member where username='$username' and password='$password'";
$row=mysql_fetch_array($result);
$id=$row[0];

if($checkcode != reg_check_code || empty($checkcode)){
echo "<script>alert('验证码不正确,请重新输入');window.location='index.php'</script>";
exit;
}

if($username!=$row[1] || $password!=$row[2]){
echo "<script>alert('用户名或密码有误,请重新输入');window.location='index.php'</script>";
exit;
}
?>

</body>
</html>

connect.php:
<?php
//设置数据库变量
$db_host="localhost"; //数据库主机名称,一般都为localhost
$db_user="root"; //数据库用户帐号
$db_password="myoa888"; //数据库用户密码
$db_name="wangzhan"; //数据库名称
//连接数据库
$connect=mysql_connect($db_host,$db_user,$db_password)
or die ('数据库连接失败'.mysql_error());
//选定数据库
mysql_select_db($db_name,$connect)
or die ('数据库选定失败'.mysql_error());
//执行数据库
$result=mysql_query($sql)
or die ('数据库执行失败:'.mysql_error());
?>
PHP我喜欢!

回复 #1 依然很帅 的帖子

$sql="select id,username,password from member where username='$username' and password='$password'";
$result=mysql_query($sql) or die ('数据库执行失败:'.mysql_error());
$row=mysql_fetch_array($result);

把connect.php中的$result=mysql_query($sql) or die ('数据库执行失败:'.mysql_error());删除!

回复 #1 依然很帅 的帖子

$sql="select id,username,password from member where username='$username' and password='$password'";
$result=mysql_query($sql) or die ('数据库执行失败:'.mysql_error());
$row=mysql_fetch_array($result);

把connect.php中的$result=mysql_query($sql) or die ('数据库执行失败:'.mysql_error());删除!

建议你把数据库链接写成类,分上层命令类和底层操作类。底层操作类根据数据库类型调用不数据库函数,上层的类只管操作,这样更换数据库就不用更改其它页面的代码。