I have tried looking all over the internet and using the answers provided in some of the questions, but cannot get this to work. How do I prevent PHP from inserting a duplicate record into the database? I can seem to get the echo statement of "no" to show up when a duplicate is being inserted, but cannot stop the actual duplicate record being inserted into the database.
I have tried almost everything, but nothing is working. Thank you to anyone who can help.
calender.php
<?php
if(isset($_GET['add'])){
$equipment=$_POST['equipment'];
$start=$_POST['start'];
$end=$_POST['end'];
$notes=$_POST['notes'];
$eventdate=$month."/".$day."/".$year;
$sql="SELECT * FROM bookings WHERE equipment='$equipment' AND start_time='$start' AND selected_date='$eventdate'";
$result= mysqli_query($dbconnection, $sql);
$results=mysqli_num_rows($result);
if($results>0) {
echo "no";
}
$sqlinsert="insert into bookings (equipment,start_time,end_time,notes,selected_date,date_added) values ('".$equipment."','".$start."','".$end."','".$notes."','".$eventdate."',now())";
$resultinsert=mysqli_query($dbconnection,$sqlinsert);
if($resultinsert){
echo "<span class='go'> Booking was successful </span>";
}else{
echo "Booking was not successful";
}
}
?>