How to validate all rows in a table using PHP

below is the script where i am trying to validate if the same name,
id and email exists in a table, the problem is that even if i add a
new input for each field i still get a "data already exist", how do i
fix this issue, also how to validate using regular expression for each
fields..for id i need three letters and 3 numbers using regular


//Retrieve the field values from our registration form.
$name = !empty($_POST['name']) ? trim($_POST['name']) : null;
$ccode = !empty($_POST['id']) ? trim($_POST['id']) : null;
$email = !empty($_POST['email']) ? trim($_POST['email']) : null;

$sql = "SELECT COUNT(*) AS num FROM users";
$stmt = $pdo->prepare($sql);

$stmt->bindValue(':name', $name);
$stmt->bindValue(':id', $id);
$stmt->bindValue(':email', $email);


$row = $stmt->fetch(PDO::FETCH_ASSOC);

if($row['num'] > 0){
die('The Data already exists!');


$sql = "INSERT INTO users (name, id, email) VALUES (:name, :id,
$stmt = $pdo->prepare($sql);

$stmt->bindValue(':name', $name);
$stmt->bindValue(':id', $id);
$stmt->bindValue(':email', $email);

$result = $stmt->execute();

echo 'User aadded successfully!';

<form action="sign.php" method="post">
<label for="name">Name</label>
<input type="text" id="name" name="name" required><br>
<label for="id">id</label>
<input type="text" id="" name="id" required><br>
<label for="email">Email</label>
<input type="email" id="email" name="email" required><br>
<input type="submit" name="register" value=" Click to

and how do i validate if the fields have same name., for example i
have 3 input fields, in the first field i enter the name of a person
and in the second or third field if i enter the same name an error
should display when i click the submit button, can it be done using a
for loop to check each field if it contains the same name

- Technology - Languages
+ Webmasters
+ Development
+ Development Tools
+ Internet
+ Mobile Programming
+ Linux
+ Unix
+ Apple
+ Ubuntu
+ Mobile & Tablets
+ Databases
+ Android
+ Network & Servers
+ Operating Systems
+ Coding
+ Design Software
+ Web Development
+ Game Development
+ Access
+ Excel
+ Web Design
+ Web Hosting
+ Web Site Reviews
+ Domain Name
+ Information Security
+ Software
+ Computers
+ Electronics
+ Hardware
+ Windows
+ C/C++/C#
+ VB/VB.Net
+ Javascript
+ Programming
Privacy Policy - Copyrights Notice - Feedback - Report Violation 2018 © BigHow