matt.sisto Posted April 26, 2009 Share Posted April 26, 2009 Hi, I am trying to allow clients to check the availability of the consultants before booking, but when I run my php script and it returns to the form all the input is lost. Can anyone advise me on how I can store the input, so when I return to the form the data is still there? bookingform.php <?php session_start(); if (!isset($_SESSION['username'])) { header("Location: login.php"); exit(); } if(isset($_GET['available1']) && $_GET['available1']=='true') { echo '<div id="available1true">Available: √</div>'; } if(isset($_GET['available1']) && $_GET['available1']=='false') { echo '<div id="available1false">Not Available: X</div>'; } if(isset($_GET['available2']) && $_GET['available2']=='true') { echo '<div id="available2true">Available: √</div>'; } if(isset($_GET['available2']) && $_GET['available2']=='false') { echo '<div id="available2false">Not Available: X</div>'; } if(isset($_GET['available3']) && $_GET['available3']=='true') { echo '<div id="available3true">Available: √</div>'; } if(isset($_GET['available3']) && $_GET['available3']=='false') { echo '<div id="available3false">Not Available: X</div>'; } require "dbconn2.php"; $sql="SELECT service_id, service FROM service"; $result=mysql_query($sql); $service_option=""; while ($row=mysql_fetch_array($result)) { $id=$row["service_id"]; $service=$row["service"]; $service_option.="<OPTION VALUE=\"$id\">".$service; } $sql="SELECT con_id, first_name, last_name FROM consultant"; $result=mysql_query($sql); $rconsultant_option=""; while ($row=mysql_fetch_array($result)) { $con_id=$row["con_id"]; $first_name=$row["first_name"]; $last_name=$row["last_name"]; $consultant_option1.="<OPTION VALUE=\"$con_id\">".$first_name." ".$last_name; $consultant_option2.="<OPTION VALUE=\"$con_id\">".$first_name." ".$last_name; $consultant_option3.="<OPTION VALUE=\"$con_id\">".$first_name." ".$last_name; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>SRC: Booking Form</title> <link href="master.css" rel="stylesheet" type="text/css"> <link rel="shortcut icon" type="image/ico" href="favicon.ico"> <script type="text/javascript"> <!-- function OnSubmitForm() { if(document.pressed == 'check1') { document.bookingForm.action ="checkavailability1.php"; } if(document.pressed == 'check2') { document.bookingForm.action ="checkavailability2.php"; } if(document.pressed == 'check3') { document.bookingForm.action ="checkavailability3.php"; } else if(document.pressed == 'book') { document.bookingForm.action ="book.php"; } return true; } //--> </script> </head> <body> <div id="topbanner"><h1>Salmons Reach Consultancy</h1><h2>Striving to achieve excellence</h2></div><div id="salmon"><img src="Salmon.png" /></div> <div id="loginRegister"> <a id="location" href="">Login </a>| <a href="register.php">Register</a> </div> <div id="border"> </div> <div id="quickLinks"> <ul><p> <li id="Title">QUICK LINKS</li><p> <li id="Title1"><a href="index.php"><b>HOME</b></a></li> <li><a href="work.php">Work</a></li> <li><a href="play.php">Play</a></li> <li><a href="future.php">Future</a></li> <li><a href="present.php">Present</a></li><p> <li id="Title1"><a href="history.php"><b>HISTORY</b></a></li> <li><a href="past.php">Past</a></li> <li><a href="staff.php">Staff</a></li> <li><a href="direction.php">Direction</a></li> <li><a href="destination.php">Destination</a></li><p> <li id="Title1"><a href="portfolio.php"><b>PORTFOLIO</b></a></li> <li><a href="thurrock.php">Thurrock</a></li> <li><a href="aru.php">Anglia Ruskin University</a></li> <li><a href="stgeorges.php">St Georges</a></li> <li><a href="malaysia.php">Malaysia</a></li><p> <li id="Title1"><a href="services.php"><b>SERVICES</b></a></li> <li><a href="consultancy.php">Consultancy</a></li> <li><a href="pd.php">Personal Development</a></li> <li><a href="project.php">Project Guidance and Initiation</a></li> <li><a href="od.php">Organisational Development</a></li><p> <li id="Title1"><a href="contact.php"><b>CONTACT</b></a></li> <li><a href="technical.php">Technical Support</a></li> <li><a href="regInterest.php">Register Interest For Services</a></li> <li><a href="message.php">Message Consultant</a></li><p> </ul> </div> <div id="menu"> <ul> <li><input id="button1" type="button" value="Home" onclick="parent.location = 'index.php'" /> <ul> <li><a href="work.php">[Work]</a></li> <li><a href="play.php">[Play]</a></li> <li><a href="future.php">[Future]</a></li> <li><a href="present.php">[Present]</a></li> </ul> </li> <li><input id="button2" type="button" onclick="parent.location = 'history.php'" value="History" /> <ul> <li><a href="past.php">[Past]</a></li> <li><a href="staff.php">[staff]</a></li> <li><a href="direction.php">[Direction]</a></li> <li><a href="destination.php">[Destination]</a></li> </ul> </li> <li><input id="button3" type="button" onclick="parent.location = 'portfolio.php'" value="Portfolio" /> <ul> <li><a href="thurrock.php">[Thurrock]</a></li> <li><a href="aru.php">[Anglia Ruskin University]</a></li> <li><a href="stgeorges.php">[st Georges]</a></li> <li><a href="malaysia.php">[Malaysia]</a></li> </ul> </li> <li><input id="button4" type="button" onclick="parent.location = 'services.php'" value="Services" /> <ul> <li><a href="consultancy.php">[Consultancy]</a></li> <li><a href="pd.php">[Personal Development]</a></li> <li><a href="project.php">[Project Guidance and Initiation]</a></li> <li><a href="od.php">[Organisational Development]</a></li> </ul> </li> <li><input id="button5" type="button" onclick="parent.location = 'contact.php'" value="contact" /> <ul> <li><a href="technical.php">[Technical Support]</a></li> <li><a href="regInterest.php">[Register Interest For Services]</a></li> <li><a href="message.php">[Message Consultant]</a></li> </ul> </li> <li><input id="button5" type="button" value="Back" onClick="history.go(-1)"> </li> </ul> </div> </div><div id="centerPanel1"> </div> <div id="rightPanel1"> </div> <div id="centerPanel"><div id="header">Booking Form</div><p> <div id="content"> <form name="bookingForm" method="post" onSubmit="return OnSubmitForm();"> <label id="eventStart">Event Date:</label><br /> <select id="year3" name="year" value="<?=$row['y']?>"> <?php $yeartoday = date(Y); $yearplus1 = date(Y)+1; for($y=$yeartoday;$y<=$yearplus1;$y++){ $selected = ""; $longDate = date("Y", mktime(0,0,0,1,1,$y)); if ($Year==$y){ $selected = "selected \n"; } echo "<option value=\"$y\" $selected>$longDate</option> \n"; } ?> </select> <select id="month3" name="month" value="<?=$row['m']?>"/> <?php $months = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); for ($x=1; $x <= count($months); $x++) { echo"<option value=\"$x\""; if ($x == $month) { echo " selected"; } echo ">".$months[$x-1]."</option>"; } ?> </select> <select id="day3" name="day" value="<?=$row['d']?>"> <?php for ($x= 1; $x<=31; $x++) { echo "<option"; if ($x == $day) { echo " selected"; } echo ">$x</option>"; } ?> </select> <p> <label id="service">Service:</label><br /> <select id="serviceSelect" name="service"> <option value="<?=$row['service']?>">Choose <?=$service_option?> </option> </select> </p> <p> <label id="unit">Unit:</label><br /> <input id="radioHour" type = 'Radio' name ='unit' value= 'hour'><label id="Hour">Hour</label> <input id="radioMin" type = 'Radio' name ='unit' value= 'day'><label id="Min">Day</label> </p> <label id="quantity">Quantity:</label><br/> <select id="quantSelect" name="quantity" value="<?=$row['quantity']?>"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> </select> <br /> <label id="eventStartTime">Start Time:</label><br/> <select id="hour" name="start_time_hr" value="<?=$row['start_time_hr']?>"> <option value="09">09</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> </select> <select id="minute" name="start_time_min" value="<?=$row['start_time_min']?>"> <option value="00">00</option> <option value="15">15</option> <option value="30">30</option> <option value="45">45</option> </select></p> <br /> <label id="extraInfo">Extra Information:</label><br /> <textarea id="extraInfoInput" name="content" value="<?=$row['extra_info']?>" onkeypress="return imposeMaxLength(this, 250);"></textarea> <p> <label id="con4">Consultant [1]:</label><br /> <select id="conSelect4" name="con_id1"><option value="<?=$row['con_id1']?>">Choose <?=$consultant_option1?> </option></select> <a id="con4A" href="">[+]</a> <input id= "check1" type ="submit" name="check1" onClick="document.pressed=this.value" value="check1"></p> <p><label id="con2">Consultant [2]:</label><br /> <select id="conSelect2" name="con_id2"><option value="<?=$row['con_id2']?>">Choose <?=$consultant_option2?> <p></option></select> <a id="con2A" href="">[+]</a> <input id= "check2" type ="submit" name="check2" onClick="document.pressed=this.value" value="check2"/></p> <label id="con3">Consultant [3]:</label><br /> <select id="conSelect3" name="con_id3"><option value="<?=$row['con_id3']?>">Choose <?=$consultant_option3?> </option></select> <a id="con3A" href="">[+]</a> <input id= "check3" type ="submit" name="check3" onClick="document.pressed=this.value" value="check3"/></p> <p><input id="book" type ="submit" name="book" onClick="document.pressed=this.value" value="book"/></form> </div> <div id="copyright">Salmons Reach Consultancy LLP ©, All rights reserved. Any duplication of property or misrepresentation will result in a judicial procedure.<p></div> </div> <div id="rightPanel"> </div> <div id="sideLogo"> <img src="sideLogo.png"/></div> </body> </html> checkavailibilty1.php <?php session_start(); if (!isset($_SESSION['username'])) { header("Location: login.php"); exit(); } require "dbconn2.php"; $month = mysql_real_escape_string($_POST["month"]); $day = mysql_real_escape_string($_POST["day"]); $year= mysql_real_escape_string($_POST["year"]); $con_id1= mysql_real_escape_string($_POST["con_id1"]); $event_start = $year."-".$month."-".$day." ".$_POST["event_start"]; $sql = "SELECT * FROM calendar_events WHERE event_start='".$event_start."' AND (con_1='".$con_id1."' OR con_2='".$con_id1."' OR con_3='".$con_id1."')"; $result = mysql_query ($sql, $connection) or die ("Could not perform query $sql <br />".mysql_error()); $row = mysql_fetch_array($result); if ($row != null){ $url = "Location: bookingform.php?available1=false"; header($url); } else { $url = "Location: bookingform.php?available1=true"; header($url); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Check Availability</title> </head> <body> </body> </html> Appreciate any help. Thanks and regs. Quote Link to comment https://forums.phpfreaks.com/topic/155764-solved-php-validating-my-booking-form-but-losing-the-input-on-return/ Share on other sites More sharing options...
premiso Posted April 26, 2009 Share Posted April 26, 2009 Store the data in session, and use the session variables on the form if there is a value stored in there. And please, refrain from using CAPS in titles, it is annoying as all hell and will not get you "quick" help as it signifies that you believe your post is more important than everyone elses on the forum and that you should get more attention. Quote Link to comment https://forums.phpfreaks.com/topic/155764-solved-php-validating-my-booking-form-but-losing-the-input-on-return/#findComment-819931 Share on other sites More sharing options...
matt.sisto Posted April 26, 2009 Author Share Posted April 26, 2009 Thanks, sorry about the caps lock thing, it wasn't my intention to highlight any specific importance its just late and I'm tired. Thanks again for the advice. I'll remember not to use caps lock again. Quote Link to comment https://forums.phpfreaks.com/topic/155764-solved-php-validating-my-booking-form-but-losing-the-input-on-return/#findComment-819932 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.