Jump to content

[SOLVED] Check database for fully booked session before submitting


biggieuk

Recommended Posts

Hi all,

 

Currently my form performs a validation function when the submit button is clicked.

 

                  <input name="Submit" type="submit" id="Submit" value="Submit">


<form action="confirmation.php" method="post" enctype="multipart/form-data" name="booking" id="booking" onSubmit="return checkRadios()">

 

How can i also check with my MYSQL database to see if 'capacity' is the same as 'placesbooked' and display an error message to the user saying which sessions are fully booked and return to the form so they can change their selection?

 

I am trying to do this so that people do not book themselves onto a session that is already filled.

 

Thanks for help with this,

 

Dan

Im looking to explore Ajax within the next few weeks, for this i just need a quick working solution so that i can get it finished.

 

Currently after pressing submit, a confirmation page is loaded displaying the details from the page before. I would need to have a page in between that could check the session capacity is not full before proceeding, otherwise the page is displayed showing the error and a back button so they can return to the booking form?

basic idea:

 

confirmation.php

if(isset($_POST['Submit'])) {

$capacity = get the value, either from your form or your database;
$placesbooked = get the value, either from your form or your database;

if($capacity - $placesbooked < 0) {
echo 'error!';
} else {
//store the values from your form temporarily in a session (don't forget to start it!)
$_SESSION['value'] = $_POST['value'];
header("Location: confirm.php");
}

confirm.php

echo '<p>Your trip is succesfully booked</p>';
echo '<p>Your details were: <ul>';
echo '<li>'.$_SESSION['value'].'</li>';
echo '</ul>';
etc

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.