N30Cr0n Posted July 2, 2007 Share Posted July 2, 2007 Hi guys, I am costructing a booking form for work, and have almost all of the code working. The problem is, I had the 'save booking' page done, which would take the values from a form on another page, and add them to a database for use on the site. that worked perfectly, until i tried to add error checking into it, so that 2 things could not be booked at the same time/date/day etc. Below is the code for the savebooking.php, and everything after the '} else { doesnot work, so it will not add records any more. any ideas? <?php $pagename = "- Save Booking"; include( "./includes/header.php" ); // form post data vars $self = $_SERVER['PHP_SELF']; $roomname = $_POST['roomname']; $roomid = $_POST['room']; $date = $_POST['date']; $week = $_POST['week']; $day = $_POST['day']; $period = $_POST['period']; $year = $_POST['year']; $subject = $_POST['subject']; $name = $_POST['name']; // end // javascript redirector back to booking page echo "<script type=\"text/javascript\">\n" ."<!--\n" ."function redirection(){\n" ."window.location=\"./" . $roomid . "_bookings.php\"\n" ."}\n" ."//-->\n" ."</script>\n\n"; echo "<body onLoad=\"setTimeout('redirection()', 7500)\">\n\n"; //end $dbcnx=@mysql_connect( $dbhost, $dbuname, $dbpword ) or die( "<center><font color=\"red\"><b>ERROR: Could not connect to server, username and/or password incorrect. Try Again</b></font></center>" ); $rs=@mysql_select_db( $dbase, $dbcnx ) or die( "<center><font color=\"red\"><b>ERROR: Could not select database, does not exist. Try Again</b></font></center>" ); $sqlread="SELECT * FROM " . $roomid . "_bookings"; $rsread=mysql_query( $sqlread, $dbcnx ); while ( $rowread=mysql_fetch_array( $rsread ) ) { $dateread=stripslashes($rowread['date']); $weekread=stripslashes($rowread['week']); $dayread=stripslashes($rowread['day']); $periodread=stripslashes($rowread['period']); if ( $dateread == "$date" and $weekread == "$week" and $dayread == "$day" and $periodread == "$period" ) { echo "<table border=\"0\" width=\"90%\" cellpadding=\"5\" cellspacing=\"5\" align=\"center\">\n" ."<tr><td align=\"left\" class=\"headerborder\" bgcolor=\"#cccccc\">Previous Booking Found</td><tr>\n" ."<tr><td width=\"100%\" class=\"tableborder\" align=\"center\">\n\n" ."<table border=\"0\" width=\"75%\" cellpadding=\"5\" cellspacing=\"5\" align=\"center\">\n" ."<tr><td width=\"100%\">I'm sorry, but there is already a previous lesson timetabled for <b>$week</b>, <b>$day</b> <b>$date</b>, <b>$period</b>. Please return to the <a href=\"./" . $roomid . "_bookings.php\" target=\"_top\">" . $roomname . " Booking Sheet</a> and try again.</td></tr>\n" ."<tr><td width=\"100%\">This page should automatically return to the $roomname booking page in approx. 7 seconds, if it does not, please <a href=\"./" . $roomid . "_bookings.php\" target=\"_top\">Click Here</a></td></tr>\n" ."</table>\n\n" ."</td></tr>\n" ."</table>\n\n"; } elseif ( $dateread != "$date" and $weekread !="$week" and $dayread != "$day" and $periodread != "$period" ) { if ( $date and $week and $day and $period and $year and $subject and $name ) { # ensure values exist $sqlin="INSERT INTO " . $roomid . "_bookings ( date, week, day, period, year, subject, name ) values ( \"$date\", \"$week\", \"$day\", \"$period\", \"$year\", \"$subject\", \"$name\" )"; $rsin=mysql_query( $sqlin, $dbcnx ); echo "<table border=\"0\" width=\"90%\" cellpadding=\"5\" cellspacing=\"5\" align=\"center\">\n" ."<tr><td align=\"left\" class=\"headerborder\" bgcolor=\"#cccccc\">Booking Saved</td><tr>\n" ."<tr><td width=\"100%\" class=\"tableborder\" align=\"center\">\n\n" ."<table border=\"0\" width=\"75%\" cellpadding=\"5\" cellspacing=\"5\" align=\"center\">\n" ."<tr><td width=\"100%\">Thank you $name, your booking has been saved, and the details are shown below.</td></tr>\n" ."<tr><td>\n\n" ."<table border=\"0\" width=\"75%\" cellpadding=\"5\" cellspacing=\"5\" align=\"center\" class=\"tableborder\">\n" ."<tr><td width=\"25%\" align=\"right\">Room:</td><td width=\"35%\" align=\"left\"><b>$roomname</b></td><td width=\"15%\" align=\"right\">Date:</td><td width=\"25%\" align=\"left\"><b>$date</b></td></tr>\n" ."<tr><td align=\"right\">Week:</td><td align=\"left\" colspan=\"3\"><b>$week</b></td></tr>\n" ."<tr><td align=\"right\">Day:</td><td align=\"left\"><b>$day</b></td><td align=\"right\">Period:</td><td align=\"left\"><b>$period</b></td></tr>\n" ."<tr><td align=\"right\">Year Group:</td><td align=\"left\"><b>$year</b></td><td align=\"right\">Subject:</td><td align=\"left\"><b>$subject</b></td></tr>\n" ."<tr><td align=\"right\">Teacher:</td><td align=\"left\" colspan=\"3\"><b>$name</b></td></tr>\n" ."</table>\n\n" ."</td></tr>\n" ."<tr><td width=\"100%\">This page should automatically return to the $roomname booking page in approx. 7 seconds, if it does not, please <a href=\"./" . $roomid . "_bookings.php\" target=\"_top\">Click Here</a></td></tr>\n" ."</table>\n\n" ."</td></tr>\n" ."</table>\n\n"; } } } include( "./includes/footer.php" ); ?> Thanks Guys N30Cr0n Quote Link to comment https://forums.phpfreaks.com/topic/58042-save-record-script-not-working-help/ Share on other sites More sharing options...
N30Cr0n Posted September 6, 2007 Author Share Posted September 6, 2007 *bump Quote Link to comment https://forums.phpfreaks.com/topic/58042-save-record-script-not-working-help/#findComment-342773 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.