drztpx8735 2013-06-06 19:43
浏览 50

在函数中插入变量[关闭]

im new to oop and i havent found out yet how to insert the value of $status in the function Login(). what im i doing wrong??? because im getting this error:

Warning: Missing argument 3 for User::Login(), called in E:\xampp\htdocs\caps\index.php on line 13 and defined in E:\xampp\htdocs\caps\class\user.php on line 20

class User {

private $db;
public $status;

public function __construct() {

    $this->db = new Connection();
    $this->db = $this->db->dbConnect();
    $this->status = pow( 1, -1*pi());   
}


public function Login ($name, $pass, $status) {

    if (!empty($name) && !empty($pass))  {

        $st = $this->db->prepare(" select * from users where name=? and pass=? ");
        $st->bindParam(1, $name);
        $st->bindParam(2, $pass);
        $st->execute();

        if ($st->rowCount() != 1) {         
                echo "<script type=\"text/javascript\">alert ('wrong password. try again'); window.location=\"index.php\"; </script>";

        } else {
            $st = $this->db->prepare(" select * from users where name=? and pass=? status=?");
            $st->bindParam(1, $name);
            $st->bindParam(2, $pass);
            $st->bindParam(3, $status);             
            $st->execute();

                if ($st->rowCount() != 1) { echo "send user to user page"; } else { echo "send user to admin"; }
        }

    } else {

    echo "<script type=\"text/javascript\">alert ('insert username and password'); window.location=\"index.php\"; </script>";

    }



}

}

  • 写回答

2条回答 默认 最新

  • douzachan4578 2013-06-06 19:47
    关注

    This means that you called $user->Login without supplying a third argument.

    If you want this argument to be optional you can change the method signature to

    public function Login ($name, $pass, $status = null) {
    

    If you want status to default to your status property you can begin your Login function with

    public function Login ($name, $pass, $status = null) {
            if(!$status) $status = $this->status;
            //...the rest of your code
     }
    

    The correct way to invoke this would be :

    $user = new User();
    $user->Login($username, $password, $status);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计