Hey all,
I am having a problem with one of my pages i used to run. The new webmaster changed a few email addy's on a fdew of the PHP pages and now the query is not working correctly. The problem I am having is when a user enters a last name and ONLY a last name the search comes up with nothing. It still works just fine when they enter the firstname and/or the district... here is the code on the find.html page where they enter the data...
<form action="findmem.php" method="post" name="form1" id="form1">
<br />
<h3 align="center"><font color="#0000FF" face="Arial, Helvetica, sans-serif">Search for OATA Member's:</font></h3>
<p><font size="3" face="Arial, Helvetica, sans-serif">Last
Name:
<input name="lastname" type="text" id="lastname" />
</font></p>
<p><font size="3" face="Arial, Helvetica, sans-serif">First
Name:
<input name="firstname" type="text" id="firstname" />
</font></p>
<p><font size="3" face="Arial, Helvetica, sans-serif">District:</font>
<select name="district" id="district">
<option value="None" selected="selected">None
<option value="nw">NW
<option value="ne">NE
<option value="c">C
<option value="se">SE
<option value="sw">SW
<option value="e">E
<option value="os">OS-out of state
</select>
</p>
<p>
<input type="submit" name="Submit" value="Begin Search" />
</p>
</form>
Here is the code for the PHP page findmem.php that the form calls:
<?php
mysql_connect("localhost","username","password");
@mysql_select_db("database") or die( "Unable to select database");
if(mysql_error())
echo mysql_error();
$lastname = $_POST['lastname'];
$firstname = $_POST['firstname'];
$district = $_POST['district'];
$query="SELECT * FROM membinfo WHERE id > 1";
// default condition, im assuming u have a field in table called id, else use the primary key
if($lastname!="")
$query = $query." AND lastname like '".$lastname."%'";
if($firstname!="")
$query = $query." AND firstname like '".$firstname."%'";
if($district == "None") {
}else{
$query = $query." AND district = '".$district."'";
}
$query = $query." ORDER BY lastname";
$result=mysql_query($query) or die (mysql_error ());
if(mysql_num_rows($result)==0){
print ("No results found. Check your search parameters and try again.");
}else{
// do the results display
}
?>
<?
while ($row = mysql_fetch_array($result)) // this will grab the results from query
{
?>
</p>
<p></p>
<table>
<tr>
<td>
<? echo $row['Id']; ?>
</td>
<td>
<font color="#0000FF" size="3" face="Arial, Helvetica, sans-serif"><strong><? echo $row['lastname']; ?>, <? echo $row['firstname']; ?></strong></font><br>
<strong><font size="3" face="Arial, Helvetica, sans-serif">District:</font></strong> <? echo $row['district']; ?><br>
<strong><font size="3" face="Arial, Helvetica, sans-serif">Work Place:</font></strong> <? echo $row['workplace']; ?><br>
<strong><font size="3" face="Arial, Helvetica, sans-serif">Work Address:</font></strong> <? echo $row['workaddress']; ?><br>
<strong><font size="3" face="Arial, Helvetica, sans-serif">Work City, State, Zip:</font></strong> <? echo $row['workcitystatezip']; ?><br>
<strong><font size="3" face="Arial, Helvetica, sans-serif">Work Phone:</font></strong> <? echo $row['work']; ?><br>
<strong><font size="3" face="Arial, Helvetica, sans-serif">Email Address: </font></strong> <a href="mailto: <? echo $row['email']; ?>"> <? echo $row['email']; ?> </a><br />
<font size="2" face="Arial, Helvetica, sans-serif">(<a href="memlogin.php">Update your information <font color="#0000FF">here</font></a>) </font><br>
<hr width=75%></td>
</tr>
<?
}
?>
I have never had a problem with this before. If noone sees any issues here I assume it is a problem with the upload of the database file to the MySQL db. I will do some more checking on that as well...
thanks for your help!
Jon