# Search SQL with PHP in 2 fields (really help wanted)

**URL:** <https://forum.kirupa.com/t/search-sql-with-php-in-2-fields-really-help-wanted/227635>\
**Category:** programming\
**Created:** [May 31, 2007, 9:48pm UTC](https://forum.kirupa.com/t/search-sql-with-php-in-2-fields-really-help-wanted/227635 "2007-05-31T21:48:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stedem](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@stedem](https://forum.kirupa.com/u/stedem)\
**Post date:** [May 31, 2007, 9:48pm UTC](https://forum.kirupa.com/t/search-sql-with-php-in-2-fields-really-help-wanted/227635/1 "2007-05-31T21:48:27Z")

</div>

I have a flower shop and would like to fit this function in my simple site  
First i will explain how my database is made (really simple, I’m a beginner :hoser:)

Oke, here we go, i’ll do my best to explain it as good as possible

I have a database called : mysite  
In this database i have a table called : products  
In this table there are 4 field : id (primary key), name, productnumber & description

Example  
Product a : 1, Rose, flowers54587, is red and small  
Product b : 2, Sunflower, flowers54584, a sunflower is yellow and big  
Product c : 3, Snowdrop, flowers54874, a snowdrop is white and tiny  
Product d : 4, Daisy, flowers54583, a daisy is yellow butt small

You can visit the flowers by browsing to the page product.php?productnumber=flowers54874

I want to create like on this site a search box to look for in the database. When i enter in the box “yellow” i would like to view all the results with the link to the product page. The search machine should look in all 4 fields to find the products (about 1500 products)

Example, when you search yellow you get the product b and d.  
I would like to have it like this:

You searched for “yellow”  
We have 2 results:  
Rose : Click to view item (product.php?productnumber=flowers54587)  
Daisy : Click to view item (product.php?productnumber=flowers54583)

This is what i have now:

# Page 1 : index.php \<form method=“post” action=“search.php”\> \<input type=“row\_name1” name=“search” size=“25”\> \<input type=“submit” value=“Begin Searching!!”\> \</form\>

Page 2 : search.php  
\<?  
$hostname = “localhost”;  
$dbName = “mysite”;  
$username = “xxxxxxx”;  
$password = " xxxxxxx ";  
$usertable = “products”;

# MYSQL\_CONNECT($hostname, $username, $password) OR DIE(“Unable to connect to database”); @mysql\_select\_db( “$dbName”) or die( “Unable to select database”); ?\> \<? //error message (not found message) $XX = “No Record Found”; $query = mysql\_query(“SELECT \* FROM $usertable WHERE $\_POST[metode] LIKE ‘%$search%’ LIMIT 0, 30 “); while ($row = mysql\_fetch\_array($query)) { $variable1=$row[“name”]; print (“this is for $variable1”); } //below this is the function for no record!! if (!$variable1) { print (”$XX”); } //end ?\>

It would be great if you could help me to fix the probably stupid mistake  
Really thanks and hope to hear soon from you, i can’t wait to view what i did wrong.

=) Greeting from Steven (Belgium, Europe)
