我是php和mysqli编程的新手,我创建了登录和注册表格。我在互联网上进行了一些有关编码以及如何完成编码的研究,当我尝试注册用户时,在将信息插入mysql数据库时遇到问题。我收到消息“ SQLSTATE [HY093]:无效的参数编号:参数未定义”
require_once 'dbconfig.php';
class USER
{
private $conn;
public function __construct()
{
$database = new Database();
$db = $database->dbConnection();
$this->conn = $db;
}
public function runQuery($sql)
{
$stmt = $this->conn->prepare($sql);
return $stmt;
}
public function lasdID()
{
$stmt = $this->conn->lastInsertId();
return $stmt;
}
public function register($uname,$email,$upass,$code,$spol)
{
try
{
$password = md5($upass);
$stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass,tokenCode,spol)
VALUES(:user_name, :user_mail, :user_pass, :active_code, :spol)");
$stmt->bindparam(":user_mail",$email);
$stmt->bindparam(":user_pass",$password);
$stmt->bindparam(":spol",$spol);
$stmt->bindparam(":active_code",$code);
$stmt->execute();
return $stmt;
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}
public function login($email,$upass)
{
try
{
$stmt = $this->conn->prepare("SELECT * FROM tbl_users WHERE userEmail=:email_id");
$stmt->execute(array(":email_id"=>$email));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() == 1)
{
if($userRow['userStatus']=="Y")
{
if($userRow['userPass']==md5($upass))
{
$_SESSION['userSession'] = $userRow['userID'];
return true;
}
else
{
header("Location: index.php?narobe");
exit;
}
}
else
{
header("Location: index.php?inactive");
exit;
}
}
else
{
header("Location: index.php?error");
exit;
}
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}
public function is_logged_in()
{
if(isset($_SESSION['userSession']))
{
return true;
}
}
public function redirect($url)
{
header("Location: $url");
}
public function logout()
{
session_destroy();
$_SESSION['userSession'] = false;
}
我不确定我是否在mysql表中犯了错误,或者我只是键入了错误的代码。 如果有人可以帮助我解决问题,那将是惊人的。
这是mysql表的图像
答案 0 :(得分:1)
您需要将$ uname参数添加到绑定参数中,忘记了一行代码:
$password = md5($upass);
$stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass,tokenCode,spol)
VALUES(:user_name, :user_mail, :user_pass, :active_code, :spol)");
$stmt->bindparam(":user_name",$uname);
$stmt->bindparam(":user_mail",$email);
$stmt->bindparam(":user_pass",$password);
$stmt->bindparam(":spol",$spol);
$stmt->bindparam(":active_code",$code);
$stmt->execute();
您不应使用 MD5 作为密码的哈希,而应使用内置函数php password_hash()和 password_verify() >