Hi all,
I have a problem with a search i want to make in a database, to search it i use a input field for the value(example: John Doe) and a list box for the type (example: Name). Im trying to get the results in the same page by using a self submission, this is the code i use for it :
code for search.php:
<?php
if (!IsSet($post))
{
?>
<form method="POST" action="search.php">
<p>
<br>
<input type="text" name="searchvalue" size="20"> <select size="1" name="searchtype">
<option>Name</option>
<option>Adress</option>
</select><br>
<br>
<br>
<br>
<input type=hidden name=post value=1>
<input type="submit" value="Submit" name="Submit"></p>
</form>
<?php
}
else
{
$sqlhostname = "localhost";
$login = "login";
$password = "password";
$base = "databasename";
$db_connect = mysql_connect($sqlhostname,$login,$password);
$base_selection = mysql_select_db($base,$db_connect);
$query = "select name, adress from members where " . $searchtype . " like '" . $searchvalue . "%'";
$result = mysql_query($query);
while ($found=mysql_fetch_array($result))
{
print ("$found[0] $found[1], $found[2]\n");
}
print ("Testing the else statement");
}
?>
What am i doing wrong ?
I already checked the seach query by declaring $searchtype and $searchvalue in the code, without the input. It works OK.
I also tried to convert the UTF-8 coding to plain PHP lines, that wasn't the problem either. I think its something that goes wrong with passing the value's since the test print doesn't print. Can someone help me with this ??