Your use of
[php]if(!empty($_POST[‘firstName’])){ [/php]
is not correct.
First of all I would use the locally assigned variable instead of the superglobal (only becuase I find it a pain to keep typing the format for the Superglobal array, and it cannot be included directly in a quoted statement).
Additionally, you are saying if $_POST[‘firstName’] is NOT empty then execute the first section which DOES NOT include firstname, else execute the second section which DOES include firstname.
The first part of the if is not the problem, If $_POST[‘firstName’] is NOT empty (thus it does have data) then you don’t use it’s value in the execution of the first query. if $_POST[‘firstName’] IS empty (No Data) then you execute the second query which is looking for data that doesn’t exist.
So you can either leave it like you have and switch the queries around or you can change your IF statement. Below is how I would do it.
[php]
<!doctype html public “-//W3C//DTD HTML 4.0 //EN”>
Search Results
<?
$lastName == !empty($_POST['lastName']) ? $_POST['lastName'] : '' ;
$firstName == !empty($_POST['firstName']) ? $_POST['firstName'] : '' ;
$conn = mysql_connect(works but cannot reveal);
mysql_select_db("status", $conn);
if($firstName==''){
$query = "SELECT * FROM results WHERE lastName LIKE '%$lastName%'";
} else {
$query = "SELECT * FROM results WHERE lastName LIKE '%$lastName%' AND firstName LIKE '%$firstName'";
}
$result = mysql_query($query, $conn);
print "
n";
print "n";
while ($field = mysql_fetch_field($result)){
print " $field->name | n";
}
print "
nn";
while ($row = mysql_fetch_assoc($result)){
print "n";
foreach ($row as $col=>$val){
print " $val | n";
}
print "
nn";
}
print "
n";
?>
[/php]