My question is that I am practicing creating things to be learned and I have doubts if you can modify the errors that PHP sends you, for example:
The error that PHP would give would be this: SQLSTATE [23000]: Integrity constraint violation: 1062 Duplicate entry 'example' for key 'userid'
And I want to know if I can modify it to my liking so that it says for example: "That value is already registered."
SOLVED but I have another question: I did this verifier work correctly but I do not know if I did it in the best possible way.
try{
$conexion=new PDO("mysql:host=localhost;dbname=privatedata","root","");
$conexion->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql="SELECT * FROM users WHERE userid= :userid";
$useridchecker=$conexion->prepare($sql);
$userid=htmlentities(addslashes($_POST['usuario']));
$useridchecker->bindValue(":userid", $userid);
$useridchecker->execute();
$uidcheck=$useridchecker->rowCount();
if ($uidcheck!=0){
echo "El usuario ingresado ya fue registrado, escoga otro.";
}else{
$sql1="SELECT * FROM users WHERE email= :email";
$emailchecker=$conexion->prepare($sql1);
$email=htmlentities(addslashes($_POST['email']));
$emailchecker->bindValue(":email", $email);
$emailchecker->execute();
$echeck=$useridchecker->rowCount();
if ($echeck!=0) {
echo "El correo ingresado ya fue registrado, escoga otro.";
}else{
$userf=$_POST['usuario'];
$emailf=$_POST['email'];
$passf=$_POST['password'];
$sql2="INSERT INTO users (userid,email,pass) VALUES ('$userf','$emailf','$passf')";
$registrar=$conexion->prepare($sql2);
$registrar->execute();
header("Location: ../login.php");
}
}
}catch (Exception $e){ die("El error es: " . $e->getMessage()); }