I am new, and about to pull my hair out (if I had any that is)
I have set up a database on a localhost for my work.
I made an html form and a php file to insert new rows in the table, and all is fine.
Now I am trying to make a search work.
My html seach form is this:
<html>
<title>Search Units</title>
<body>
<table align="center"><tr><td align="center"><h1>Search Units</h1><br><br>
<form action="search.php" method="post">
Search <select name="field">
<option value="first">First Name</option>
<option value="last">Last Name</option>
<option value="phone">Phone</option>
<option value="street">Street Address</option>
<option value="city">City</option>
<option value="state">State</option>
<option value="zip">Zip Code</option>
<option value="units">Units</option>
</select>
For <input type="text" name="value">
<input type="submit" value="SEARCH">
</form>
</td></tr></table>
</body>
</html>
And my search.php code is this:
<?
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("unable to connect to database");
$field=$_POST['field'];
$value=$_POST['value'];
$query="SELECT * FROM units WHERE '$field'='$value'";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
echo"<b><center>Search Results</center></b><br><br>";
$i=0;
while($i<$num)
{
$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$phone=mysql_result($result,$i,"phone");
$street=mysql_result($result,$i,"street");
$city=mysql_result($result,$i,"city");
$state=mysql_result($result,$i,"state");
$zip=mysql_result($result,$i,"zip");
$units=mysql_result($result,$i,"units");
$comments=mysql_result($result,$i,"comments");
$service=mysql_result($result,$i,"service");
$date=mysql_result($result,$i,"date");
echo"<b>$first $last</b><br>$street<br>$city $state, $zip<br>$phone<br><br>$units<br>$date<br>$comments<br>$service<br><hr><br>";
$i++;
}
?>
My table columns are the same as the value of the options in the drop down of the form.
Help please