I have created two level of registration in my website, in first level of registration I can store my value in database but in second level I can't store in the same table.
In first register I have used an insert query, in second level of register in same table, I have used an update query.
If I given direct row value in where condition I am able to store, in case if I give as user_id
I should not accept.
First register:
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();
}
}
second register:
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();
}
}
Thanks in advance
3 Errors in your code
user_id =':user_id'
into user_id =:user_id
,i.e remove single quotesbindparam
to user_id,i.e $stmt->bindparam(":user_id", $user_id);
Try to change this code
public function register($uname,$umail,$upass,$mobile,$gender,$user_id)
{
try
{
$new_password = password_hash($upass, PASSWORD_DEFAULT);
$stmt = $this->conn->prepare("INSERT INTO users(user_name,user_email,user_pass,mobile,gender,user_id)
VALUES(:uname, :umail, :upass, :mobile, :gender, :user_id )");
$stmt->bindparam(":uname", $uname);
$stmt->bindparam(":umail", $umail);
$stmt->bindparam(":upass", $new_password);
$stmt->bindparam(":mobile", $mobile);
$stmt->bindparam(":gender", $gender);
$stmt->bindparam(":user_id", $user_id);
$stmt->execute();
return $stmt;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
Second Registration
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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With