php求解,为什么出错?

@Ta 2012-12-17 3756点击
密码对了也显示登陆失败,是验证登路页面、
<?php
include "conn.php";
include "head.php";
$pwd=$_POST["pwd"];
$user=$_POST['username'];
$md5pwd=md5(md5(md5($pwd)));
if($pwd==NULL || $user==NULL)
{
exit('请输入帐号密码');
}
$sql=mysql_query("select username,password from user where username='$username' and password='$md5pwd'",$connect);
$fetch=mysql_fetch_array($sql);
if($sql)
{
echo 'sql执行成功';
}else{
echo '执行失败';
}
if($fetch<>0)
{
echo '登陆成功';
echo $fetch['uid'];
}else{
echo '登陆失败';
}
?>
回复列表(10|隐藏机器人聊天)
  • @Ta / 2012-12-17 / /
    不懂飘过~~
  • @Ta / 2012-12-17 / /
    $fetch=mysql_fetch_array ($sql);这是取数组的,不是取条数的,改用mysql_num_rows取条数
  • @Ta / 2012-12-17 / /
    @许繁 其实用密码对比更好
  • @Ta / 2012-12-17 / /
    这样对比么?$fetch['username']==$username @
  • @Ta / 2012-12-17 / /
    在数据库中取出username数组,用你四楼的语句判断用户名是否存在再用密码进行比对,
  • @Ta / 2012-12-17 / /
    <?php include "conn.php"; include "head.php"; $pwd=$_POST["pwd"]; $user=$_POST['username']; $md5pwd=md5(md5(md5($pwd))); if($pwd==NULL || $user==NULL) { exit('请输入帐号密码'); } $sql=mysql_query ("select username,password from user where username='$username'", $connect);  $row=mysql_fetch_array($sql);  if($name<>$row{'name'}){  echo "该账号不存在";}elseif($md5pass<>$row['password']){  echo '密码错误';}else{  echo '登陆成功'; }  ?> @许繁
  • @Ta / 2012-12-17 / /
    <?php include "conn.php"; include "head.php"; $pwd=$_POST["pwd"]; $user=$_POST['username']; $md5pwd=md5(md5(md5($pwd))); if($pwd==NULL or $user==NULL){ exit('请输入帐号密码'); } $sql=mysql_query ("select username,password from user where username='$username'", $connect);  $row=mysql_fetch_array($sql);  if($name<>$row{'name'}){  echo "该账号不存在";}elseif($md5pwd<>$row['password']){  echo '密码错误';}else{  echo '登陆成功'; }  ?>
  • @Ta / 2012-12-17 / /
    不对额、俄:echo  $fetch [ 'password' ];
     echo  $fetch [ 'username' ];
    没输出任何数据,sql语句是不是错了?
  • @Ta / 2012-12-17 / /
    看8楼 @
  • @Ta / 2012-12-17 / /
    @ 谢谢,非常感谢,已解决,嘿嘿,
添加新回复
回复需要登录