View Full Version : php mysql form

11-07-2002, 02:13 PM
I have a quick beginner question. i have a form (search.php) that you input, in one box address number and in the other street name. Now i want to click submit which will take to say "results.php" How do I write a MYSQL statement that will search the database, "warren" in table "contacts" in fields "number" and "street" for the street number and name entered in the previous page. Can anyone show me the way.

11-07-2002, 03:01 PM
maybe something like this:

SELECT * FROM contacts WHERE number LIKE %warren% OR street LIKE %warren%;

11-07-2002, 11:45 PM
Sorry, I mis understood the question, the correct SQL would be as follows:

In your code create a variable that is from the posted form

$searchTerm = $_POST['street'];

(Assumes your form has an input field like)

<input tpye="text" name="street" />

then your sql will need to be
SELECT * FROM contacts WHERE street LIKE %$searchTerm%;

the php code would be something like:

$passwd="YOUR PASSWORD";
$linkID = mysql_connect("localhost","$usr", "$passwd");
if ($linkID != FALSE) {
mysql_select_db("$db", $linkID);
$sqlID = mysql_query("SELECT * FROM contacts WHERE street LIKE %'$searchTerm'%", $linkID);
if($sqlID) {
print $data['FIELD FROM DATABASE'];

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum