$newuser->check($_POST['user'],$_POST['pass'])

解决方案 »

  1.   

    感觉你对类认识不够好,注意php的连接符是'.',而非'+'。:-).
    ===========================
    class user{
    public $name;
    public $pwd;
    public function user($username,$password){
    $this->name=$username;
    $this->pwd=$password;
    }
    public function check(){
    mysql_select_db("php",$conn);
    $exec="select count(*) from yonghu where username='".$this->name."'and pwd='".$this->pwd."'";
    $reslut=mysql_query($exec,$conn);
    if($reslut>0){
    echo "用户验证通过";
    }
    else {
    echo "用户名或密码错误";}
    }
    }
      

  2.   

    用时:
    ======================
    $userChk = new user($_POST['username'],$_POST['pass']);
    $userChk->check();
      

  3.   

    $exec="select count(*) from yonghu where username="+$username+ "and pwd="+$password;
    ,首先此sql错误
      

  4.   

    $reslut=mysql_query($exec,$conn);
    if($reslut>0){
    echo "用户验证通过";
    }
    else {
    echo "用户名或密码错误";}
    $result是true或false,判断条件有问题
      

  5.   

    mysql_query($exec,$conn);
    如果查询到数据,此函数会返回一个"资源"(resource)类型.否则返回false;所以判断要这样写:
    if($reslut)
       echo "用户验证通过";
    else 
       echo "用户名或密码错误";
    按你那种写法也可以,不过要这样写:
    if(mysql_num_rows($reslut) > 0)
       echo "用户验证通过";
    else 
       echo "用户名或密码错误";
    多去看看面向对象的思想,你这样用类不如不用.mysql_connect为什么不放到Conn类里面封装起来?数据库查询应该也放到Conn类里面,数据检验用一个类,而检验的应该是数据的完整性及合理性.
      

  6.   

    谢谢各位指点啊!小地知道了,现在刚开始看php之前,没有过面向对象开发经验所以....不好意思~~~~ ,努力中......放分先~!