Hello All:

I am trying to check to see if a certain date is already booked before I enter a new record
with that same date into my DB. When I test this no matter what the args are, I get this error message:


DBD::mysql::st execute failed: Duplicate entry '3' for key 1 at dateDiff2.pl line 201.

Key 1 is a unique reservation Id that gets generated every time the script is called.
I tried changing this number manually but still get the same error.


TIA,

Tom Castonzo

<snip>

my ($count) = 0;


# Make sure we are not double-booking a reservation $sth2 = $dbh->prepare(" SELECT house_num,start_date,end_date FROM reservations WHERE house_num = ? AND start_date = ? AND end_date = ? ");

$sth2->bind_param(1,$rental);
$sth2->bind_param(2,$$sql_date_1);
$sth2->bind_param(3,$$sql_date_2);


# See if $count gets incremented from 0 to > 0 $count = $sth2->execute();

#If so, we have am existing reservation with the same start and end date
if($count > 0) {

#Exit script
&abort_now("Reservation conflicts with an existing record in the database.. Use the back button and try again\n");
}


else {

# This query will insert a new reservation record into the database
$sth3 = $dbh->prepare("INSERT INTO reservations (reservation_num,cust_num,house_num,start_date,end_date)
VALUES (?,?,?,?,?)");


    $sth3->bind_param( 1, $reservation_id);
    $sth3->bind_param( 2, $cust_id);
    $sth3->bind_param( 3, $rental);
    $sth3->bind_param( 4, $$sql_date_1);
    $sth3->bind_param( 5, $$sql_date_2);


$sth3->execute();



} </snip>

Reply via email to