我是php的新手,我正在尝试为我的网站创建一个成员系统。我似乎在第9行("public function__construct(){")上遇到了一个错误,说"语法错误,意外的T_STRING,预期的T_VARIABLE"。如果您能帮助我解释为什么会出现这个错误,我将不胜感激。谢谢。
我的代码:
<?php
include_once('connection.php')
class User {
private $db;
public function__construct(){
$this->db = new connection ();
$this->db = $this->db->dbConnect();
}
public function Login($name, $pass){
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 "user verified access granted";
}else{
echo "Incorrect username or password";
}
}else{
echo "Please enter username and password";
}
}
}
?>
我看到两个可能的错误:
public function __construct() ...
下一个是:
用"1"answers"2"绑定时替换1、2
我也遇到了同样的问题。我的错误是省略了function__construct(){}
中function
关键字和双下划线之间的空格。关于这一点,你还需要注意的一件事是,你必须在函数符号或()上加上大括号。
尝试函数_construct()而不是函数_construct()