I have a small time slot booking system, where I can click a link called: Reserve, and then I reserve that given time.
However, the page doesn't refresh after I've clicked on reserve. Therefore it's possible for a user to click the same reserve link twice. Whitch they shouldn't be able to.
if (isset ( $_GET ['reserved'] )) {
$sqlreserve = "INSERT INTO calendar (eventDate, timeslot) VALUES ('" . $dateToCompare . "','" . intval($_GET['t']) . "');";
$resultreserve = mysqli_query ( $mysqli1, $sqlreserve );
if ($resultreserve) {
header('Location: '.$_SERVER['PHP_SELF']);
} else {
echo "Event Failed to add";
}
}
If my insert works, then I call: header('Location: '.$_SERVER['PHP_SELF']);
I'm working on localhost, if that has anything to say?
EDIT:
The way I create my links and the text saying that a slot is booked is like this:
if (mysqli_num_rows ( $result ) == 0) {
echo "<a href='" . $_SERVER ['PHP_SELF'] . "?month=" . $month . "&day=" . $day . "&year=" . $year . "&t={$time}&v=true&f=true&reserved=true'><h3 style='color: rgb(255,0,0);'>Reserve</h3></a>";
} else {
echo "<h3>Not Available, taken by:</h3>";
while ( $row = mysqli_fetch_array ( $result ) ) {
echo "<br />";
}
}
EDIT. My Error:
Cannot modify header information - headers already sent by (output started.....)
for($i = 1; $i < $numDays; $i ++, $counter ++) {
$timeStamp = strtotime ( "$year-$month-$i" );
if ($i == 1) {
$firstDay = date ( "w", $timeStamp );
for($j = 0; $j < $firstDay; $j ++, $counter ++) {
echo "<td> </td>";
}
}
if ($counter % 7 == 0) {
echo "</tr><tr>";
}
$monthstring = $month;
$monthlength = strlen ( $monthstring );
$daystring = $i;
$daylength = strlen ( $daystring );
if ($monthlength <= 1) {
$monthstring = "0" . $monthstring;
}
if ($daylength <= 1) {
$daystring = "0" . $daystring;
}
$todaysDate = date ( "m/d/Y" );
$dateToCompare = $monthstring . '/' . $daystring . '/' . $year;
echo "<td align='center' ";
if ($todaysDate == $dateToCompare) {
echo "class='today'";
} else {
$sqlCount = "SELECT * FROM calendar WHERE eventDate='" . $dateToCompare . "'";
$noOfEvent = mysqli_num_rows ( mysqli_query ( $mysqli1, $sqlCount ) );
if ($noOfEvent >= 1) {
echo "class='event'";
}
}
echo "><a href='" . $_SERVER ['PHP_SELF'] . "?month=" . $monthstring . "&day=" . $daystring . "&year=" . $year . "&v=true'>" . $i . "</a></td>";
}
The line affected is:
echo "><a href='" . $_SERVER ['PHP_SELF'] . "?month=" . $monthstring . "&day=" . $daystring . "&year=" . $year . "&v=true'>" . $i . "</a></td>";
It is in another file where I have my calendar, in which I have links to the specific day that I wan't to book the timeslots fore: