Hi, I have a problem. I would like to, from a text form, filter out what the user wants to see. I have a mysql database with info on every order placed. Each row is a new order. All users has their own ID. I would like the users to enter their ID and click collect and the database will show all orders with that ID.

Here's my code so far:

<?php
if ($searchstring)
	{
	$sql="SELECT * FROM Blad1 WHERE '%$searchstring%' = ID";
	include('connect.php');
	$result = mysql_query($sql,$db);
	echo "<table border=1 align=center cellspacing=2 cellpadding=3>\n";
    echo "<TR><TH>Referens<TH>ID<TH>Kund</TR>\n";
	while ($rad = mysql_fetch_array($result))
		{
		echo "<TR><TD>$rad[referens]<TD>$rad[ID]<TD>$rad[Kund]\n";		
		}
	echo "</TABLE>";
	}
else
	{
	?>
<form method="POST" action="<?php $PHP_SELF ?>">
	
  <table border="1" align="center" cellspacing=2 cellpadding=3>
    <tr><td>Sök här</td>
	
    </tr>
	<tr>
	<td><input type="text" name="searchstring" size="40"></td>
	
	</tr>
	</table>
	
  <p align="center">
    <input type="submit" value="Search" name="B1">
    <input type="reset" value="Clear" name="B2">
  </p>
	</form>
	
<?php
	}
?>

Recommended Answers

All 2 Replies

WHERE '%$searchstring%' = ID is rather tricky. If a user enters ID = 1 then every ID with a 1 in it is returned. 1, 10, 11, and so on. If you remove the % signs, it will search for an exact match.

Thanks!

Problem solved!

Regards
Magnus

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.