【发布时间】:2017-06-24 06:04:25
【问题描述】:
我在我的网站中创建了两级注册,在第一级注册中我可以将我的值存储在数据库中,但在第二级我不能存储在同一个表中。
在第一个寄存器中我使用了插入查询,在同一张表的第二级寄存器中,我使用了更新查询。
如果我在可以存储的条件下给出直接行值,以防我给出user_id 我不应该接受。
第一次注册:
public function register($uname,$umail,$upass,$mobile,$gender)
{
try
{
$new_password = password_hash($upass, PASSWORD_DEFAULT);
$stmt = $this->conn->prepare("INSERT INTO users(user_name,user_email,user_pass,mobile,gender)
VALUES(:uname, :umail, :upass, :mobile, :gender )");
$stmt->bindparam(":uname", $uname);
$stmt->bindparam(":umail", $umail);
$stmt->bindparam(":upass", $new_password);
$stmt->bindparam(":mobile", $mobile);
$stmt->bindparam(":gender", $gender);
$stmt->execute();
return $stmt;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
第二个寄存器:
public function register1($marital_status,$applicant_photo,$date_of_birth,$home_name,$birth_time)
{
try
{
$stmt = $this->conn->prepare("UPDATE users SET marital_status= :marital_status, applicant_photo=:applicant_photo, date_of_birth=:date_of_birth, home_name=:home_name, birth_time=:birth_time WHERE user_id =':user_id'");
$stmt->bindparam(":marital_status", $marital_status);
$stmt->bindparam(":applicant_photo", $applicant_photo);
$stmt->bindparam(":date_of_birth", $date_of_birth);
$stmt->bindparam(":home_name", $home_name);
$stmt->bindparam(":birth_time", $birth_time);
$stmt->execute();
return $stmt;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
提前致谢
【问题讨论】:
-
缺少绑定user_id stmt->bindparam(":user_id", $user_id);并删除单引号 user_id =':user_id'
-
你把
user_id绑定到register1的什么地方了? -
基本上就是 JYoThl 所说的。一般来说,请查看
$this->conn->error了解更多信息。try...catch不会捕获错误,因为mysqli默认情况下不会抛出错误。 -
我不知道“为什么这个问题得到了 5 票”