Jump to content

stop empty field from display


SkyRanger

Recommended Posts

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

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";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.