Jump to content

stop empty field from display


Go to solution Solved by QuickOldCar,

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";
Edited by SkyRanger
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.