0

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
	}
?>
2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by bubbelhund
0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.