
PHP Registration Form Using PDO Prepared Statement
Code below code for a better explanation visit our youtube channel at https://www.youtube.com/channel/UCtTjECvLAA5NkyjgVTTC5eQ
<?php
require_once("pdo_db_conn.php");
if (isset($_POST['form_submit'])) {
// code...
$name = $_POST['form_name'];
$email = $_POST['form_email'];
$password = $_POST['form_password'];
//check if email exist
try{
$check = $pdo->prepare("SELECT * FROM registration WHERE email = ?");
$check->execute([$email]);
if ($check->rowCount()>0) {
// code...
echo "<center style='color:red'>Email exist try another</center>";
}else{
try{
$insert = $pdo->prepare("INSERT INTO registration(name,email,password)VALUE(?,?,?)");
if($insert->execute([$name,$email,$password])){
echo "<center style='color:green;'>Successful</center>";
}
}catch(PDOException $e){
echo $e->getMessage();
}
}
}catch(PDOException $e){
echo $e->getMessage();
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Registration Form</title>
</head>
<body>
<center>
<form action="registration.php" method="post">
<h1>Registration Form!</h1>
<input type="text" name="form_name" placeholder="Full name" required><br><br>
<input type="email" name="form_email" placeholder="Email address" required><br><br>
<input type="password" name="form_password" placeholder="Password" required><br><br>
<input type="submit" name="form_submit" value="Register">
</form>
</center>
</body>
</html>