SkyRanger Posted July 18, 2015 Share Posted July 18, 2015 I am having a problem when a user just hits submit on an empty field and having all entries displayed. Is there a way to stop this with the code I have and go right to the else { if ( isset( $_POST['hp-submitted'] ) ) { // sanitize form values $houseaddy = sanitize_text_field( $_POST["haddy"] ); global $wpdb; #$results = $GLOBALS['wpdb']->get_results("SELECT * FROM locations where stname='$houseaddy'"); $rowhs = $wpdb->get_results( "SELECT * FROM locations where stname like '%" . $houseaddy ."%'"); if (!empty($rowhs)) { foreach ( $rowhs as $rowhs ) { echo "<br />"; echo "<p><b><font color=\"#92AEFE\" size=\"4\">Report Address: </font><font size=\"4\">"; echo $rowhs->stname . ", " . $rowhs->hcity ." ". $rowhs->hprov . "</font></b><br>"; echo "<b><font size=\"4\" color=\"#92AEFE\">Report Number: </font><font size=\"4\">" . $rowhs->hid ."</font></b><br>"; echo "<b><font size=\"4\" color=\"#92AEFE\">Date of Report: </font><font size=\"4\">" . $rowhs->datepost ."</font></b></p>"; } } else { echo "0 entries available"; echo "<br /><br />"; } } Link to comment https://forums.phpfreaks.com/topic/297346-stop-empty-field-from-display/ Share on other sites More sharing options...
inversesoft123 Posted July 18, 2015 Share Posted July 18, 2015 Hello trim it and check it is blank or no. if(trim($_POST["haddy") != "") { Link to comment https://forums.phpfreaks.com/topic/297346-stop-empty-field-from-display/#findComment-1516681 Share on other sites More sharing options...
SkyRanger Posted July 18, 2015 Author Share Posted July 18, 2015 Perfect thank you, that fixed one problem but caused another. Now when box is empty goes to else { echo "0 entries available"; but when somebody enters an entry that does not exist just shows blank. Is there a way to combine if (!empty($rowhs)) { with if(trim($_POST["haddy"]) != "") { to show else { echo "0 entries available"; Link to comment https://forums.phpfreaks.com/topic/297346-stop-empty-field-from-display/#findComment-1516715 Share on other sites More sharing options...
QuickOldCar Posted July 18, 2015 Share Posted July 18, 2015 if (!empty($rowhs) && trim($_POST["haddy"]) != "") { Link to comment https://forums.phpfreaks.com/topic/297346-stop-empty-field-from-display/#findComment-1516716 Share on other sites More sharing options...
SkyRanger Posted July 18, 2015 Author Share Posted July 18, 2015 Awesome, just what I was looking for thank you very much Link to comment https://forums.phpfreaks.com/topic/297346-stop-empty-field-from-display/#findComment-1516717 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.