Hello,
Newbie here, creating table search, returns all records when nothing is entered into search box, and no results when anything is entered. Thanks for your help. This forum is awesome.
<?php
// connection information
$hostName = "";
$userName = "";
$password = "";
$dbName = "member";
// make connection to database
mysql_connect($hostName, $userName, $password) or die( "Unable to connect to host $hostName");
mysql_select_db($dbName) or die( "Unable to select database $dbName");
// Select all the fields in all the records of the table
$query =
"SELECT *
FROM member
WHERE ((COMPANY LIKE '$search%')
and (CONTACT LIKE '$search%')
and (CITY LIKE '$search%')
and (STATE LIKE '$search%')
and (ZIP LIKE '$search%'))
ORDER BY MEMBERID -1";
$result = mysql_query($query);
// Determine the number of members
$number = mysql_numrows($result);
if ($number == 0) {
print "Sorry, there were no records matching those criteria";
} else {
// Print the member names
for($i=0; $i<$number; $i++){
$MEMBERID = mysql_result($result,$i, 'MEMBERID');
$COMPANY = mysql_result($result,$i, 'COMPANY');
$CONTACT = mysql_result($result,$i, "CONTACT");
$CITY = mysql_result($result, $i, "CITY");
$STATE = mysql_result($result, $i, "STATE");
$ZIP = mysql_result($result, $i, "ZIP");
print "$MEMBERID, $COMPANY, $CONTACT, $CITY,
$STATE, $ZIP<br>";
}
}
// Close the database connection
mysql_close();
?>
The form:
<form name="form1" method="post" action="search.php3">
<center>
Search For Text:
<select name="select">
<option value="$search" selected>Company</option>
<option value="CONTACT">Contact</option>
<option value="CITY">City</option>
<option value="STATE">State</option>
<option value="ZIP">Zip</option>
</select>
<input type=text name=search id=$search size=25>
<input type="submit" name="Submit" value="Submit">
</center>
</form>