chornbeck
02-07-2006, 09:07 PM
Need a little noob help here.. I'm running this query which should search my MySQL DB and return only the records that have the same last name and a first name that begins with the first initial that the person enters. It works fine to look up the last name, but when I try to add on the first initial, it craps out. I'm having a problem with the proper wildcards, I believe, but maybe my PHP is flawed as well.. Take a look if you would...
<?
if($_POST['submit'])
{
mysql_connect("localhost","orlandoi_referra","referral2");
mysql_select_db("orlandoi_referralowners") or die ('I cannot connect to the database because: ' . mysql_error());
$LstName = make_safe($_POST['LstName']);
$FirstInitial = make_safe($_POST['FirstInitial']);
$result = mysql_query("SELECT * FROM owner_data WHERE LastName = '$LstName' AND FirstName like '% FirstInitial%% %'") or die(mysql_error());
?>
<table width="600" border="1" cellspacing="0" cellpadding="2">
<tr>
<th scope="col">First</th>
<th scope="col">Last</th>
<th scope="col">Zip</th>
<th scope="col">OwnerID</th>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td><?php echo " ".$row['FirstName'];?></td>
<td><?php echo " ".$row['LastName'];?></td>
<td><?php echo " ".$row['PostalCode'];?></td>
<td bgcolor="#fffc00"><b><?php echo " ".$row['OwnerID'];?></b></td>
</tr>
<?php
}
}
function make_safe($variable)
{
$variable = addslashes(trim($variable));
return $variable;
}
?>
<?
if($_POST['submit'])
{
mysql_connect("localhost","orlandoi_referra","referral2");
mysql_select_db("orlandoi_referralowners") or die ('I cannot connect to the database because: ' . mysql_error());
$LstName = make_safe($_POST['LstName']);
$FirstInitial = make_safe($_POST['FirstInitial']);
$result = mysql_query("SELECT * FROM owner_data WHERE LastName = '$LstName' AND FirstName like '% FirstInitial%% %'") or die(mysql_error());
?>
<table width="600" border="1" cellspacing="0" cellpadding="2">
<tr>
<th scope="col">First</th>
<th scope="col">Last</th>
<th scope="col">Zip</th>
<th scope="col">OwnerID</th>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td><?php echo " ".$row['FirstName'];?></td>
<td><?php echo " ".$row['LastName'];?></td>
<td><?php echo " ".$row['PostalCode'];?></td>
<td bgcolor="#fffc00"><b><?php echo " ".$row['OwnerID'];?></b></td>
</tr>
<?php
}
}
function make_safe($variable)
{
$variable = addslashes(trim($variable));
return $variable;
}
?>