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
https://forums.phpfreaks.com/topic/175011-need-help-with-simple-search/
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 ;)

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.