Jump to content

Recommended Posts

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>

 

 

Link to comment
https://forums.phpfreaks.com/topic/167978-solved-do-nothing-if-blank/
Share on other sites

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.

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

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.