dennismonsewicz Posted November 21, 2008 Share Posted November 21, 2008 I have the following code: echo $e_display; echo '<p>Select your state</p>'; echo '<form action="tmotier.php?action=make" method="post">'; echo '<select name="state" onChange="this.form.submit();">'; echo '<option value=""></option>'; $test_qry = mysql_query("SELECT * FROM tbl_name")or die(mysql_error()); while($row = mysql_fetch_object($test_qry)) { echo '<option value="' . $row->state_abbr . '">' . $row->state_abbr . '</option>'; } echo '</select>'; echo '<input type="submit" value="Submit" />'; echo '</form>'; the $e_display var is being set like so: if(empty($_POST['state'])) { $e_display = '<p style="color: red">You must select a state to continue!</p>'; } else { $e_display = ''; } Well when you load the page the error message is still displayed even if you have not submitted anything.. any ideas? Link to comment https://forums.phpfreaks.com/topic/133711-solved-error-checking-help/ Share on other sites More sharing options...
flyhoney Posted November 21, 2008 Share Posted November 21, 2008 Im not completely sure, but since state is a string and not an array it might be better to do this: <?php if ($_POST['state']) { $e_display = '<p style="color: red">You must select a state to continue!</p>'; } else { $e_display = ''; } ?> Link to comment https://forums.phpfreaks.com/topic/133711-solved-error-checking-help/#findComment-695816 Share on other sites More sharing options...
PFMaBiSmAd Posted November 21, 2008 Share Posted November 21, 2008 All of your form validation and processing code should be enclosed in a conditional statement that checks if the form was submitted. This is commonly done by giving your submit button a name="...." parameter and then checking that the corresponding $_POST['....'] variable is set. echo '<input type="submit" name="submit" value="Submit" />'; if(isset($_POST['submit'])){ // your form was submitted // do your form validation and processing here } Link to comment https://forums.phpfreaks.com/topic/133711-solved-error-checking-help/#findComment-695827 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.