Search from database?

hi everyone,

i got a little problem searching from a database… : http://www.roy.lu/futura/

you can click on “afficher les produits” in order to view the db…

the first form is used to insert products into the db.

in the 2nd from (on the bottom), i would like to be able to search either by product reference or product name, how can i achieve this?

index.php:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<body>

<p>ajouter un produit</p>
<form action="insert.php" method="post">
Reference: <input type="text" name="ref" />
Nom: <input type="text" name="nom" />
Poids: <input type="text" name="poids" />
<input type="submit" />
</form>

<p>
<a href="http://www.roy.lu/futura/results.php">afficher les produits</a>
</p>

<p>chercher un produit</p>
<form  method="post" action="search.php?go"  id="searchform">
	<input  type="text" name="name">
	<input  type="submit" name="submit" value="Search">
</form>

</body>
</html>

search.php:


<?php
	  if(isset($_POST['submit'])){
	  if(isset($_GET['go'])){
	  if(preg_match("/^[  a-zA-Z]+/", $_POST['name'])){
	  $name=$_POST['name'];
	  //connect  to the database
	  $db=mysql_connect  ("localhost","db","pw") or die ('I cannot connect to the database  because: ' . mysql_error());
	  //-select  the database to use
	  $mydb=mysql_select_db("db");
	  //-query  the database table
	  $sql="SELECT  ID, Reference, Nom FROM Products WHERE Reference LIKE '%" . $name .  "%' OR Nom LIKE '%" . $name ."%'";
	  //-run  the query against the mysql query function
	  $result=mysql_query($sql);
	  //-create  while loop and loop through result set
	  while($row=mysql_fetch_array($result)){
	          $Reference =$row['Reference'];
	          $Nom=$row['Nom'];
	          $ID=$row['ID'];
	  //-display the result of the array
	  echo "<ul>\
";
	  echo "<li>" . "<a  href=\\"search.php?id=$ID\\">"   .$Reference . " " . $Nom .  "</a></li>\
";
	  echo "</ul>";
	  }
	  }
	  else{
	  echo  "<p>Please enter a search query</p>";
	  }
	  }
	  }
	?>

in the 2nd from (on the bottom), i would like to be able to search either by product reference or product name, how can i achieve this?

What is the problem with the code you have?

when searching a reference (numerical) nothing happens… when searching a word I get an error message about mysql_fetch_array… you may try out hte thing by following the link above