Jump to content

Need Help With Simple Search


spock9458

Recommended Posts

I am trying to get a simple search to work, using input from a form entry.  I have found tutorials and here is my very basic first try:

 

<form method="post" action="contact_search.php">
See if your name is listed as a Contact in our database:
<br><br>
Enter your full name and click the "Search" button:<br>
<input type="text" name="search" size="50"><br>
<br><input type="submit" value="Search"></input>
</form>

 

Anyway, the first line of "contact_search.php" says "if ($search) {..." and goes through the mysql query code after the bracket.  The 'else' code is just an echo that says "The search string is empty..." When I try to do a search, that is what I get - the message saying my search string is empty.  Obviously something is wrong with my code and the string is not getting assigned to "$search"... I'm sure it's something simple, but can someone help?

 

Thanks

Link to comment
Share on other sites

The tutorial you are working from seems to be old, and relies on globals being on

 

several things;

$search needs to be assigned (and validated)

<?php
$search = mysql_escape_string($_POST['search']); // assuming it is used in a database query

 

another thing, you could post the rest of the code to make sure we are assuming correct ;)

Link to comment
Share on other sites

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.