geroid Posted May 10, 2009 Share Posted May 10, 2009 I have this validation code to check if values are empty and return a form if any are. The problem is that it keeps returning the form even though there are no empty elements. I've echoed the variables to prove that they all contain values. Is there something wrong with my if else statement in this code. The code seems long but really I'm only concerned with why it is not inserting the record after valiodation is confirmed with the if empty function. Just skip past all the form code to the else statement at the end of the page if you can help. Thanks if (empty($_session['evname']) || empty($_session['venuename']) || empty($_session['addr1']) || empty($_session['town']) || empty($_session['county']) || empty($_session['content']) || empty($_session['day']) || empty($_session['month']) || empty($_session['year']) || empty($_session['time'])) { ?><BR><h3>It appears you forgot to enter your complete details below. Please remember that <font color=red><EM>ALL</EM></font> fields are required. </h3><BR> <font size=2 color=green> Please finalise the details below and select </font><font size=2 color=red>'Submit'.</font><BR><BR> <form id="form1" method="post" action="submit_new_event.php"> <table><tr><TD></TD><td><font color="#666666"><b>Event Title: </font></td> <td><input type="text" name="eventtitle" size="50" value=<?echo $_SESSION['evname'] ?>></td></tr> <tr><TD></TD><td><font color="#666666"><b>Venue Name: </font></td> <td><input type="text" name="venuename" size="50" value=<?echo $_SESSION['venuename'] ?>></td></tr> <tr><TD></TD><td><font color="#666666"><b>Street Address: </font></td> <td><input type="text" name="addr1" size="50" value=<?echo $_SESSION['addr1'] ?>></td></tr> <tr><TD></TD><td><font color="#666666"><b>Town: </font></TD> <td><input type="text" name="town" size="50" value=<?echo $_SESSION['town'] ?>></td></tr> <tr><TD></TD><td><font color="#666666"><b>County: </font></TD> <td><input type="text" name="county" size="25" value=<?echo $_SESSION['county'] ?>></td></tr> <tr><TD></TD><td><font color="#666666"><b>Event Description: </font></TD> <TD><textarea cols="40" rows="12" wrap="hard" name="content" value=""> <?php echo $_SESSION['content']; ?> </textarea></TD></TR></TABLE><BR><BR> <TABLE><TR><TD><font color="#666666"><b>Event Date and Time:</font></td></TR> <TR><td></TD><td nowrap="true"><font color="#666666"><b>Day</b></font></td> <TD><select name="day"> <option value="" selected="selected">--</option> <option value="01" >01</option> <option value="02" >02</option> <option value="03" >03</option> <option value="04" >04</option> <option value="05" >05</option> <option value="06" >06</option> <option value="07" >07</option> <option value="08" >08</option> <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> <option value="17" >17</option> <option value="18" >18</option> <option value="19" >19</option> <option value="20" >20</option> <option value="21" >21</option> <option value="22" >22</option> <option value="23" >23</option> <option value="24" >24</option> <option value="25" >25</option> <option value="26" >26</option> <option value="27" >27</option> <option value="28" >28</option> <option value="29" >29</option> <option value="30" >30</option> <option value="31" >31</option> </select></TD></tr><td></td> <TR><td></TD><td nowrap="true"><font color="#666666"><b>Month</b></font></td> <TD><select name="month"> <option value="" selected="selected">----------------</option> <option value="01" >January</option> <option value="02" >February</option> <option value="03" >March</option> <option value="04" >April</option> <option value="05" >May</option> <option value="06" >June</option> <option value="07" >July</option> <option value="08" >August</option> <option value="09" >September</option> <option value="10" >October</option> <option value="11" >November</option> <option value="12" >December</option></select></TD></tr><td></td> <tr><td></TD><td nowrap="true"><font color="#666666"><b>Year</b></font></td> <TD><select name="year"> <option value="" selected="selected">----</option> <option value="2009">2009</option> <option value="2010">2010</option> <option value="2011">2011</option> <option value="2012">2012</option> <option value="2013">2013</option> <option value="2014">2014</option> <option value="2015">2015</option> <option value="2016">2016</option> <option value="2017">2017</option> <option value="2018">2018</option> <option value="2019">2019</option> <option value="2020">2020</option> <option value="2021">2021</option> <option value="2022">2022</option> <option value="2023">2023</option> <option value="2024">2024</option> <option value="2025">2025</option> </select></td></tr> <tr><td></TD><td nowrap="true"><font color="#666666"><b>time</b></font></td> <TD><select name="time"> <option value="" selected="selected">----</option> <option value="7:00">7:00</option> <option value="7:15">7:15</option> <option value="7:30">7:30</option> <option value="7:45">7:45</option> <option value="8:00">8:00</option> <option value="8:15">8:15</option> <option value="8:30">8:30</option> <option value="8:45">8:45</option> <option value="9:00">9:00</option> <option value="9:15">9:15</option> <option value="9:30">9:30</option> <option value="9:45">9:45</option> <option value="10:00">10:00</option> <option value="10:15">10:15</option> <option value="10:30">10:30</option> <option value="10:45">10:45</option> <option value="11:00">11:00</option> <option value="11:15">11:15</option> <option value="11:30">11:30</option> <option value="11:45">11:45</option> <option value="12:00">12:00</option> <option value="12:15">12:15</option> <option value="12:30">12:30</option> <option value="12:45">12:45</option> <option value="13:00">13:00</option> <option value="13:15">13:15</option> <option value="13:30">13:30</option> <option value="13:45">13:45</option> <option value="14:00">14:00</option> <option value="14:15">14:15</option> <option value="14:30">14:30</option> <option value="14:45">14:45</option> <option value="15:00">15:00</option> <option value="15:15">15:15</option> <option value="15:30">15:30</option> <option value="15:45">15:45</option> <option value="16:00">16:00</option> <option value="16:15">16:15</option> <option value="16:30">16:30</option> <option value="16:45">16:45</option> <option value="17:00">17:00</option> <option value="17:15">17:15</option> <option value="17:30">17:30</option> <option value="17:45">17:45</option> <option value="18:00">18:00</option> <option value="18:15">18:15</option> <option value="18:30">18:30</option> <option value="18:45">18:45</option> <option value="19:00">19:00</option> <option value="19:15">19:15</option> <option value="19:30">19:30</option> <option value="19:45">19:45</option> <option value="20:00">20:00</option> <option value="20:15">20:15</option> <option value="20:30">20:30</option> <option value="20:45">20:45</option> <option value="21:00">21:00</option> <option value="21:15">21:15</option> <option value="21:30">21:30</option> <option value="21:45">21:45</option> <option value="22:00">22:00</option> <option value="22:15">22:15</option> <option value="22:30">22:30</option> <option value="22:45">22:45</option> <option value="23:00">23:00</option> <option value="23:15">23:15</option> <option value="23:30">23:30</option> <option value="23:45">23:45</option> <option value="24:00">24:00</option> <option value="24:15">24:15</option> <option value="24:30">24:30</option> <option value="24:45">24:45</option> <option value="1:00">1:00</option> <option value="1:15">1:15</option> <option value="1:30">1:30</option> <option value="1:45">1:45</option> <option value="2:00">2:00</option> <option value="2:15">2:15</option> <option value="2:30">2:30</option> <option value="2:45">2:45</option> <option value="3:00">3:00</option> <option value="3:15">3:15</option> <option value="3:30">3:30</option> <option value="3:45">3:45</option> <option value="4:00">4:00</option> <option value="4:15">4:15</option> <option value="4:30">4.30</option> <option value="4:45">4:45</option> <option value="5:00">5:00</option> <option value="5:15">5:15</option> <option value="5:30">5:30</option> <option value="5:45">5:45</option> <option value="6:00">6:00</option> <option value="6:15">6:15</option> <option value="6:45">6:45</option> </select></td></tr></TABLE> <BR><BR> <TABLE ><TR><TD width=450 align="right"><input id="inputsubmit1" class="highlightit" type="submit" name="ccdetails" value="Submit" /></TD></TR></TABLE></form> <? }else{ //Format date and address and insert the new event record then redirect to confirmation page $_SESSION['fulldate'] = $_SESSION['year']."-". $_SESSION['month']."-".$_SESSION['day']; $_SESSION['fulladdr'] = $_SESSION['addr1']. ", ".$_SESSION['town']. ", ".$_SESSION['county'] ;?> <? $insert = mysql_query("insert into $table (event_name, venue_name, streetaddress1, town, county, event_description, event_date, event_time) values ('" .$_SESSION['evname']. "', '".$_SESSION['venuename']."', '".$_SESSION['addr1']."', '".$_SESSION['town']."', '".$_SESSION['county']."', '".$_SESSION['content']."', '".$_SESSION['fulldate']."', '".$_SESSION['time']."')") or die("Could not insert data because ".mysql_error()); if (!headers_sent()) { header("Location: confirm_add_event.php"); }else { $redirect = '<script type="text/javascript">window.location = "confirm_add_event.php";</script>'; $redirect .= '<noscript><meta type="refresh" content="0;url=confirm_add_event.php" /></noscript>'; echo $redirect; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/157573-if-else-statement-not-working-please-help/ Share on other sites More sharing options...
herghost Posted May 10, 2009 Share Posted May 10, 2009 try this: <?php } else { //Format date and address and insert the new event record then redirect to confirmation page $_SESSION['fulldate'] = $_SESSION['year']."-". $_SESSION['month']."-".$_SESSION['day']; $_SESSION['fulladdr'] = $_SESSION['addr1']. ", ".$_SESSION['town']. ", ".$_SESSION['county'] ; $insert = mysql_query("insert into $table (event_name, venue_name, streetaddress1, town, county, event_description, event_date, event_time) values ('" .$_SESSION['evname']. "', '".$_SESSION['venuename']."', '".$_SESSION['addr1']."', '".$_SESSION['town']."', '".$_SESSION['county']."', '".$_SESSION['content']."', '".$_SESSION['fulldate']."', '".$_SESSION['time']."')") or die("Could not insert data because ".mysql_error()); if (!headers_sent()) { header("Location: confirm_add_event.php"); }else { $redirect = '<script type="text/javascript">window.location = "confirm_add_event.php";</script>'; $redirect .= '<noscript><meta type="refresh" content="0;url=confirm_add_event.php" /></noscript>'; echo $redirect; } } ?> are you getting any mysql errors? Quote Link to comment https://forums.phpfreaks.com/topic/157573-if-else-statement-not-working-please-help/#findComment-830951 Share on other sites More sharing options...
geroid Posted May 10, 2009 Author Share Posted May 10, 2009 No Herghost, that had no effect at all - same problem. I know these session variables contain values for sure as I'm echoing them back so I'm a little stumped. Any more ideas? Quote Link to comment https://forums.phpfreaks.com/topic/157573-if-else-statement-not-working-please-help/#findComment-830954 Share on other sites More sharing options...
Ken2k7 Posted May 10, 2009 Share Posted May 10, 2009 In your IF statement, it should be $_SESSION (case-sensitive). Quote Link to comment https://forums.phpfreaks.com/topic/157573-if-else-statement-not-working-please-help/#findComment-831089 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.