ubuntu Posted May 14, 2007 Share Posted May 14, 2007 Dear all, can someone help me what's wrong with my code? The problem is when I send a blank (without select any field) page, no error was display. Thank you for your kind attention. Form for user to input table cellpadding="0" cellspacing="0" border="0" width="94%" align="center"> <tr> <td valign="top"><b>From</b></td> <td valign="top"><b> : </b></td> <td valign="top"><select name="from" class="field"> <option value="-">---------- Location ----------</option> <option value="66">Kuala Lumpur</option> <option value="67">Batu Pahat</option> <option value="68">Muar</option> </select></td> </tr> <tr> <td valign="top"><b>To</b></td> <td valign="top"><b> : </b></td> <td valign="top"><select name="to" class="field"> <option value="-">---------- Location ----------</option> <option value="66">Kuala Lumpur</option> <option value="67">Batu Pahat</option> <option value="68">Muar</option> </select></td> </tr> <tr> <td valign="top"><b>Month</b></td> <td valign="top"><b> : </b></td> <td valign="top"><select name="month" class="field"> <option value="-">-----------------</option> <option value="jan">January</option> <option value="feb">February</option> <option value="mar">March</option> <option value="apr">April</option> <option value="may">May</option> <option value="jun">June</option> <option value="jul">July</option> <option value="aug">August</option> <option value="sep">September</option> <option value="oct">October</option> <option value="nov">November</option> <option value="dec">December</option> </select></td> </tr> <tr> <td valign="top"><b>Year</b></td> <td valign="top"><b> : </b></td> <td valign="top"><select name="year" class="field"> <option value="-">-----------------</option> <option value="2007">2007</option> <option value="2008">2008</option> </select></td> </tr> <tr> <td valign="top"><b>Day</b></td> <td valign="top"><b> : </b></td> <td valign="top"><select name="day" class="field"> <option value="-">-----------------</option> <option value="mon">Monday</option> <option value="tue">Tuesday</option> <option value="wed">Wednesday</option> <option value="thu">Thursday</option> <option value="fri">Friday</option> <option value="sat">Saturday</option> <option value="sun">Sunday</option> </select></td> </tr> <tr> <td valign="top"><b>Date</b></td> <td valign="top"><b> : </b></td> <td valign="top"><select name="day_of_week" class="field"> <option value="-">-----------------</option> <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> <option value="8">8</option> <option value="9">9</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> <tr> <td valign="top"><b>Time</b></td> <td valign="top"><b> : </b></td> <td valign="top"><select name="time" class="field"> <option value="-">-----------------</option> <option value="twelve">12:00pm</option> <option value="third">03:00pm</option> <option value="fifth">05:00pm</option> </select></td> </tr> <tr> <td valign="top"><b>Quantity</b></td> <td valign="top"><b> : </b></td> <td valign="top"><select name="quantity" class="field"> <option value="-">-----------------</option> <option value="one">1</option> <option value="two">2</option> </select></td> </tr> <tr><td> <input type="submit" name="submit" value="Submit"> </td></tr> </table> Code to check require field <?php $error = NULL; if($_POST['from'] == "-"){ $error .= "Error, you haven't select from field.<br>"; } if($_POST['to'] == "-"){ $error .= "Error, you haven't select to field.<br>"; } if($_POST['month'] == "-"){ $error .= "Error, you didn't select month.<br>"; } if($_POST['year'] == "-"){ $error .= "Error, you didn't select year.<br>"; } if($_POST['day'] == "-"){ $error .= "Error, you didn't select day.<br>"; } if($_POST['day_of_week'] == "-"){ $error .= "Error, you didn't select date.<br>"; } if($_POST['time'] == "-"){ $error .= "Error, you didn't select departure time.<br>"; } if($_POST['quantity'] == "-"){ $error .= "Error, you didn't select quantity.<br>"; } if (!is_null($error)) { die($error); } ?> Quote Link to comment Share on other sites More sharing options...
Garath531 Posted May 14, 2007 Share Posted May 14, 2007 What happens when you press the submit button? Does it take you to a blank screen, or does it show you the form page again? Quote Link to comment Share on other sites More sharing options...
StormTheGates Posted May 14, 2007 Share Posted May 14, 2007 I dont see any form around your table telling it to submit anywhere as POST style. Quote Link to comment Share on other sites More sharing options...
ubuntu Posted May 14, 2007 Author Share Posted May 14, 2007 When I press the submit button without any field selected, the results page appear without display the error message. Quote Link to comment Share on other sites More sharing options...
StormTheGates Posted May 14, 2007 Share Posted May 14, 2007 Change your code with stuff like this: <?php $error = NULL; if($_POST['from'] == "-"){ die("This is working so far!"); $error .= "Error, you haven't select from field.<br>"; } if($_POST['to'] == "-"){ die("This is working so far!"); $error .= "Error, you haven't select to field.<br>"; } if($_POST['month'] == "-"){ die("This is working so far!"); $error .= "Error, you didn't select month.<br>"; } if($_POST['year'] == "-"){ die("This is working so far!"); $error .= "Error, you didn't select year.<br>"; } if($_POST['day'] == "-"){ die("This is working so far!"); $error .= "Error, you didn't select day.<br>"; } if($_POST['day_of_week'] == "-"){ die("This is working so far!"); $error .= "Error, you didn't select date.<br>"; } if($_POST['time'] == "-"){ die("This is working so far!"); $error .= "Error, you didn't select departure time.<br>"; } if($_POST['quantity'] == "-"){ die("This is working so far!"); $error .= "Error, you didn't select quantity.<br>"; } if (!is_null($error)) { die($error); } ?> Tell me what happens. Quote Link to comment Share on other sites More sharing options...
ubuntu Posted May 14, 2007 Author Share Posted May 14, 2007 Bro, still the same result. Quote Link to comment Share on other sites More sharing options...
StormTheGates Posted May 14, 2007 Share Posted May 14, 2007 Aright so its not even picking up the post variables. Two more things: 1. I see in your html you lack a <form action="page.php" method="post"> </form> element? Could that be it? 2. If you have one do this at the very top do this: $var = $_POST['from']; die("+$var+"); That will tell you what is being picked up if anything. Quote Link to comment Share on other sites More sharing options...
ubuntu Posted May 14, 2007 Author Share Posted May 14, 2007 Bro, 1. My form didn't miss <form action="page.php" method="post"> </form> element. 2. The result display is: ++ Quote Link to comment Share on other sites More sharing options...
StormTheGates Posted May 14, 2007 Share Posted May 14, 2007 You sure? I just tested this code on my server: <?php if($_POST['submit']){ $test = $_POST['from']; die("+$test+"); } ?> <form action="v.php" method="post"> <table cellpadding="0" cellspacing="0" border="0" width="94%" align="center"> <tr> <td valign="top"><b>From</b></td> <td valign="top"><b> : </b></td> <td valign="top"><select name="from" class="field"> <option value="-">---------- Location ----------</option> <option value="66">Kuala Lumpur</option> <option value="67">Batu Pahat</option> <option value="68">Muar</option> </select></td> </tr> <tr> <td valign="top"><b>To</b></td> <td valign="top"><b> : </b></td> <td valign="top"><select name="to" class="field"> <option value="-">---------- Location ----------</option> <option value="66">Kuala Lumpur</option> <option value="67">Batu Pahat</option> <option value="68">Muar</option> </select></td> </tr> <tr> <td valign="top"><b>Month</b></td> <td valign="top"><b> : </b></td> <td valign="top"><select name="month" class="field"> <option value="-">-----------------</option> <option value="jan">January</option> <option value="feb">February</option> <option value="mar">March</option> <option value="apr">April</option> <option value="may">May</option> <option value="jun">June</option> <option value="jul">July</option> <option value="aug">August</option> <option value="sep">September</option> <option value="oct">October</option> <option value="nov">November</option> <option value="dec">December</option> </select></td> </tr> <tr> <td valign="top"><b>Year</b></td> <td valign="top"><b> : </b></td> <td valign="top"><select name="year" class="field"> <option value="-">-----------------</option> <option value="2007">2007</option> <option value="2008">2008</option> </select></td> </tr> <tr> <td valign="top"><b>Day</b></td> <td valign="top"><b> : </b></td> <td valign="top"><select name="day" class="field"> <option value="-">-----------------</option> <option value="mon">Monday</option> <option value="tue">Tuesday</option> <option value="wed">Wednesday</option> <option value="thu">Thursday</option> <option value="fri">Friday</option> <option value="sat">Saturday</option> <option value="sun">Sunday</option> </select></td> </tr> <tr> <td valign="top"><b>Date</b></td> <td valign="top"><b> : </b></td> <td valign="top"><select name="day_of_week" class="field"> <option value="-">-----------------</option> <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> <option value="8">8</option> <option value="9">9</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> <tr> <td valign="top"><b>Time</b></td> <td valign="top"><b> : </b></td> <td valign="top"><select name="time" class="field"> <option value="-">-----------------</option> <option value="twelve">12:00pm</option> <option value="third">03:00pm</option> <option value="fifth">05:00pm</option> </select></td> </tr> <tr> <td valign="top"><b>Quantity</b></td> <td valign="top"><b> : </b></td> <td valign="top"><select name="quantity" class="field"> <option value="-">-----------------</option> <option value="one">1</option> <option value="two">2</option> </select></td> </tr> <tr><td> <input type="submit" name="submit" value="Submit"> </td></tr> </table> </form> And it displayed fine. Quote Link to comment Share on other sites More sharing options...
Garath531 Posted May 14, 2007 Share Posted May 14, 2007 ??? This is weird. It works perfectly on my computer. About the only thing I can think of is that you are going directly to the "Pagename.php". That's the only thing I can do to get this result. ??? Quote Link to comment Share on other sites More sharing options...
ubuntu Posted May 14, 2007 Author Share Posted May 14, 2007 Thank you StormTheGates & Garath531, now it worked already. I wonder my pc got problem or not? After close the browser and reopen again, it worked. Regards. 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.