WebGuyRI Posted July 29, 2009 Share Posted July 29, 2009 Newbee question Please help I have a number of forms and if the person does not put anything in the search box I need to have it stay on that screen and not go to the database. Currently its dumping the database. Thanks in advance Bill <form action="data_blackstone.php" method="post"> <center> <font size="4" face="Arial, Helvetica, sans-serif">Surname:</font> <input type="text" name="name"/> <input type="Submit"/> </center> </form> Quote Link to comment https://forums.phpfreaks.com/topic/167978-solved-do-nothing-if-blank/ Share on other sites More sharing options...
Maq Posted July 29, 2009 Share Posted July 29, 2009 You can submit the form to the same page to check, verify, and sanitize input. Upon success, query the DB, else, display relevant error message and prompt the user again. EDIT: Please surround code with tags for proper indentation and syntax highlighting. Quote Link to comment https://forums.phpfreaks.com/topic/167978-solved-do-nothing-if-blank/#findComment-885985 Share on other sites More sharing options...
WebGuyRI Posted July 29, 2009 Author Share Posted July 29, 2009 Thanks for the reply. The code worked for one search box but not the other. Looking for 2 different items "Name" and "Maiden"from one form but not at the same time. I am going to 2 different database screens. One database screen for the name and a second database screen if its maiden Added the code suggested but not sure I have it right. Now I am getting the error message with the first query displaying on the "Name" database screen. The second query box "maiden" gives me the error message with each database listing of the return. So when the person is looking for "name" and the box is blank it displays one line of the error code. If the person is looking for "maiden" then it displays the error code with each listing of the database. This is the database page for Maiden $yourfield = "name"; $yourfield2 = "given"; $maiden = "maiden"; ini_set ("display_errors", "1"); error_reporting(E_ALL); mysql_connect($hostname, $username, $password) or DIE("Unable to connect to MySQL server $hostname"); " Connected to MySQL server<br>"; $selected = mysql_select_db($dbname) or DIE("Could not select requested db $dbname"); print "Connected to database $dbname<br>"; $maiden = mysql_real_escape_string($_POST['maiden']); $query = "SELECT * FROM $usertable WHERE maiden='$maiden'"; $result = mysql_query($query) or DIE("Could not Execute Query on table $usertable"); if ($result) { print "Query successful on table $usertable<br><br>"; print "Your Query returned:<br>"; while ($row = mysql_fetch_array($result)) { print $row['name'].", ".$row['f_name'].", (Maiden Name) ".$row['maiden'].", (Birth) ".$row['birth_d']."-".$row['birth_m']."-".$row['birth_y'].", (Death) ".$row['d_day']."-".$row['d_month']."-".$row['d_year'].",".$row['d_loc'].", (Age) ".$row['age'].", (Relationship) ".$row['r_ship'].", (Cemetery) ".$row['cemetery'].", ".$row['town'].", ".$row['state'].", (Section) ".$row['c_section'].", (Lot) ".$row['c_lot'].", (Military) ".$row['war'].", (Relationship) ".$row['relation'].", (Misc) ".$row['misc']."<br>"; } } mysql_close; ?> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/167978-solved-do-nothing-if-blank/#findComment-886016 Share on other sites More sharing options...
WebGuyRI Posted July 29, 2009 Author Share Posted July 29, 2009 Added this and it resolved mu problem if ($_POST['maiden'] == "" ) { echo 'There was an error in the data you submitted. Please go back and fill in all the required fields.'; die(); } Quote Link to comment https://forums.phpfreaks.com/topic/167978-solved-do-nothing-if-blank/#findComment-886095 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.