ProcalX Posted February 15, 2010 Share Posted February 15, 2010 I have a MYSQL database, within this database is a table that has three columns: day/month/year in this format: 10/10/2010. I am trying to validate a script so that a user cannot cancel a booking if it is 48 hours before the event, or the event has past. This is what I have so far: <?php $bookingid = $_GET["id"]; $date = strtotime(date("Y-m-d", strtotime($date)) . " +2 days"); //todays date +2 days if ($bookingid != "") { //check both events $sql = "SELECT bookings.ID AS bid, events.* FROM bookings,events WHERE bookings.id = $bookingid AND bookings.eventID = events.ID"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $eventdate = date("Y-m-d","$row[year]-$row[month]-$row[day], int mktime ([ int $hour = 0 [, int $minute = 0 [, int $second = 0 [, int $month = $row[month] [, int $day = $row[day] [, int $year = $row[year] [, int $is_dst = -1 ]]]]]]] )"); if ($eventdate < $date) { echo "Event Date: $eventdate <br /><br />"; echo "Todays Date + 2 Days: $date<br /><br />"; $sql = "SELECT * FROM bookings WHERE ID = $bookingid"; $result = mysql_query($sql); $row = mysql_fetch_array($result); if (mysql_num_rows($result)==1) { //Update quantity of tickets for event $mysql = "UPDATE events SET availability = availability + $row[ntickets] WHERE ID = $row[eventID]"; mysql_query($mysql); //Delete booking from bookings table $mysql = "DELETE FROM bookings WHERE ID = $bookingid"; mysql_query($mysql); echo "You have succesfully cancelled booking id: $bookingid"; } } else { echo "You cannot cancel a booking 48 hours before the event."; } } mysql_close($conn); ?> The script runs fine, however it does not validate properly, Event Date shows as: 1970-01-01 and Todays date + 2 days shows as: 172800. Unsure why event date is showing like this, I believe this is the earliest date that unix can handle? Quote Link to comment Share on other sites More sharing options...
Deoctor Posted February 15, 2010 Share Posted February 15, 2010 hai in ur code i dont got this query $eventdate = date("Y-m-d","$row[year]-$row[month]-$row[day], int mktime ([ int $hour = 0 [, int $minute = 0 [, int $second = 0 [, int $month = $row[month] [, int $day = $row[day] [, int $year = $row[year] [, int $is_dst = -1 ]]]]]]] )"); thw $sql doesnot have any row month or day or year.. are u sure u wrote the correct one Quote Link to comment Share on other sites More sharing options...
ProcalX Posted February 15, 2010 Author Share Posted February 15, 2010 The $sql selects all from the BOOKINGS table where the ID matches that of the bookingID, this will select everything within the bookings table subject to these parameters, which includes the columns: day / month / year. The idea here was to insert straight from the mysql_fetch_array the day / month / year straight into the PHP DATE function and store it to $eventdate variable so that the full date of the event is stored from the database into a variable within the script. This may be wrong but I am unsure how to go about this? Can you help? Quote Link to comment Share on other sites More sharing options...
Deoctor Posted February 15, 2010 Share Posted February 15, 2010 yes i can do that but u need to show me the table structure and some sample data so that i can help u out. skype me at chaitanya09986025424 Quote Link to comment Share on other sites More sharing options...
jl5501 Posted February 15, 2010 Share Posted February 15, 2010 It looks like there is more then 1 issue here, but first try changing $row = mysql_fetch_assoc($result); $eventdate = date("Y-m-d","$row['year']-$row['month']-$row['day']......... Quote Link to comment Share on other sites More sharing options...
ProcalX Posted February 15, 2010 Author Share Posted February 15, 2010 Thanks for your help but I've sorted it; Work out todays date + 2 days: $twodays = time()+60*60*24*2; This stores the date 2 days ahead of the present day in seconds then we check this against the date stored in the database via the mysql_fetch_array: $eventdate = strtotime("$row[year]-$row[month]-$row[day]"); This converts the day, month and year stored in the database into the same time format (in unix timestamp seconds) Then check against each other using an If statement. I hope this helps anyone else! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.