Can someone help me:
I got error when i write this
$check = $db->prepare("SELECT email FROM user WHERE email = ?");
if($check->rowCount() == 1){
$error = "<div class ='text-danger'> Email Telah Digunakan </div>";
} else {
$code = rand();
$status = 0;
try{
$query = $db->prepare("INSERT INTO users(first_name,last_name,email,password,gender,code,status) VALUES (?,?,?,?,?,?,?,)");
$query->execute([$first_name,$last_name,$email,password_hash($password,PASSWORD_DEFAULT),$gender,$code,$status]);
}
catch(PDOException $e){
echo"error: " .$e->getMessage();
}
}
Ok, so you have a ,
at the end of your VALUES()
's list without something after it, which would lead to such syntax error. Here is the fixed version:
$check = $db->prepare("SELECT email FROM user WHERE email = ?");
if($check->rowCount() == 1){
$error = "<div class ='text-danger'> Email Telah Digunakan </div>";
}else{
$code = rand();
$status = 0;
try{
$query = $db->prepare("INSERT INTO users(first_name,last_name,email,password,gender,code,status) VALUES (?,?,?,?,?,?,?)");
$query->execute([$first_name,$last_name,$email,password_hash($password,PASSWORD_DEFAULT),$gender,$code,$status]);
}
catch(PDOException $e){
echo "error: " .$e->getMessage();
}
}
You where also missing a closing bracket for the if
statement. Or maybe you copied wrongly. I've not actually checked full functionality, just the syntax errors I could find.
A small tip
If you format your code properly, you can find syntax errors a lot easier. A good code editor also helps.