I am making a website in which people can select which tickets they want and they just get an ID to go pay and pick them up to the desired location.
I have a PHP function that actually checks if the tickets are already booked before allowing people to reserve them, but I just found out that if 2 people happen to click the "booking" button within the same second, my system reserves the places twice.
Is there a way to prevent this? My current code works well except for what I've said, it's here:
$f1="";
$f2="";
$sqlAP="SELECT * FROM apartados";
if ($resultAP = mysql_query($sqlAP)) {
while ($rowAP = mysql_fetch_array($resultApP)) {
$f = $rowAP['funcion'];
$lugar=$rowAP['lugar'];
$count++;
if($f=="F1"){
$f1.=($lugar. " ");
}else if($f=="F2"){
$f2.=($lugar. " ");
}
}
}
$sqlPag2="SELECT * FROM pagados";
if ($resultPag2 = mysql_query($sqlPag2)) {
while ($rowPag2 = mysql_fetch_array($resultPag2)) {
$f = $rowPag2['funcion'];
$lugar=$rowPag2['lugar'];
$count++;
if($f=="F1"){
$f1.=($lugar. " ");
}else if($f=="F2"){
$f2.=($lugar. " ");
}
}
}
$func1= explode(" ",$f1);
$func2= explode(" ",$f2);
$repetidos=0;
for($int=0;$int<$cant;$int++){
$helper=0;
while($func1[$helper]){
if($func1[$helper]==$lugar[$cant]){
$repetidos++;
}
$helper++;
}
}
for($int=0;$int<$cant2;$int++){
$helper=0;
while($func2[$helper]){
if($func2[$helper]==$lugar2[$cant2]){
$repetidos++;
}
$helper++;
}
}
This takes from the database what has been booked (apartados) and paid (pagados) and then checks for repeated seats trying to get booked (repetidos) after this comes an if just looking for repetidos > 0, it works, except on the instance I described earlier. Could anyone let me know how I can avoid this?