<?php
include("conn/conn.php");
$username=@$_POST['name'];
$userpwd=@md5($_POST['pwd']);
$yz=@$_POST['yz'];
$num=@$_POST['num'];
if(strval($yz)!=strval($num)){
echo "<script>alert('验证码输入错误!');history.go(-1);</script>";
exit;
}
class chkinput{
var $name;
var $pwd;
function chkinput($x,$y){
$this->name=$x;
$this->pwd=$y;
}
function checkinput(){
include("conn/conn.php");
$sql=mysql_query("select * from tb_user where name='".$this->name."'",$conn);
$info=mysql_fetch_array($sql);
if($info==false){

echo "<script language='javascript'>alert('不存在此用户!');history.back();</script>";
exit;
}
else{
if($info[dongjie]==1){
echo "<script language='javascript'>alert('该用户已经被冻结!');history.back();</script>";
exit;
}if($info[pwd]==$this->pwd)

session_start();
$_SESSION[username]=$info[name];
session_register("producelist");
$producelist="";
session_register("quatity");
$quatity="";
header("location:index.php");
exit;
}
else {
echo "<script language='javascript'>alert('密码输入错误!');history.back();</script>";
exit;
}

}
}
$obj=new chkinput(trim($username),trim($userpwd));
$obj->checkinput();
?>
数据库已经有注册的数据,但是在首页登录界面一直提示不存在此用户,这是判断的页面,请帮忙看一下,我是PHP新手,刚学,不太懂。

解决方案 »

  1.   

    $sql=mysql_query("select * from tb_user where name='".$this->name."'",$conn);
    中的 $conn 在哪里赋值的?
    如果 $conn 没有赋值或值不是资源,那么这个句就执行失败了
    取不到值,自然就是不存在了
      

  2.   

    有啊,conn有引用,是链接数据库的代码
      

  3.   

    将$info==false改成empty($info)试一下
      

  4.   

    class chkinput{
    var $name;
    var $pwd;
    function chkinput($x,$y){
    $this->name=$x;
    $this->pwd=$y;
    }跟 $obj=new chkinput(trim($username),trim($userpwd)); 什么鬼function chkinput($x,$y){
    $this->name=$x;
    $this->pwd=$y;
    }
    要改成 function __construct($x,$y){
    $this->name=$x;
    $this->pwd=$y;
    }
    你后面实例化的时候才能正确的赋值到变量,再校验啊