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>

Michael Isijola

About Author

I am an experienced IT expert with 10+ years of experience with a track record of success in creating apps that are both well-received and commercially viable. Skilled in working as a team and incorporating input into projects, a strong eye for detail, and tenacity to never quit on something until it is absolutely perfect. Innovative use of technology for excellent delivery of tasks, ability to complete projects efficiently, and satisfy customers with attractive, user-friendly applications. And also, the ability to oversee the development and dissemination of technology for external customers, vendors, and other clients to help improve and increase business.