I am new to PHP coding for a school project where I need to enter data but check for duplicate values
for now I am checking for email address and it does find the duplicate but does not accept the additional entry when I add addtional columns Mobile and Date values the code stops entering the data but says it is successful.
when I remove the columns for the DB and reduce the code to be only be first name last name email id it works.
Any suggestions on how I can get it to enter the data for Mobile and Date would be appreciated
Index
<html>
<body>
<form name="form" method="post" action="1process.php">
<table>
<tr>
<td>First Name</td>
<td><input type="text" name="fname" required pattern="[a-zA-Z]+" /></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="lname" required pattern="[a-zA-Z]+" /></td>
<tr>
<td>Mobile</td>
<td><input type="text" name="mobile" required pattern="[a-zA-Z]+" /></td>
<tr>
<td>Email Id</td>
<td><input type="email" name="mail" required /></td>
</tr>
<tr>
<td>Date</td>
<td><input type="text" name="date" required pattern="[a-zA-Z]+" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="submit" /></td>
</tr>
</table>
</form>
</body>
<?php
PHP process
<?php
$host = "localhost";
$user = "root";
$password = "";
$database = "SurfschoolDB";
$mysqli = new mysqli($host,$user,$password,$database);
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$mobile = $_POST['mobile'];
$email = $_POST['mail'];
$date = $_POST['date'];
// Check connection
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
// Perform query
if ($result = $mysqli -> query("SELECT `email ID` FROM `customers` WHERE `email id` = '$email'")) {
echo "Returned rows are: " . $result -> num_rows . "\n";
$count = $result -> num_rows;
echo $count . "\n";
If ($count == 0) {
$mysqli -> query("INSERT INTO `customers`(`First Name`, `Last Name`, 'Mobile', 'Date', `Email Id`) VALUES ('$fname', '$lname', '$mobile', '$date', '$email')");
echo "Entered data successfully\n";
} Else {
echo "User already exists\n";
$result -> free_result();
}
}
`enter code here`$mysqli -> close();
?>