I have a script which is supposed to search my database and return results. If it finds something, it is working correctly; however, if it doesn't find anything, the test is not working right and it acts as if it DID find something.
Here's the script: - see about line 186.
----------------
<HTML>
<HEAD>
<TITLE>Huntsville High School Reunion - Class of 1980 - Huntsville, Alabama</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=
a[i])&&x.o
Src;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_pre
loadImages
.arguments
; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&p
arent.fram
es.length)
{
d=parent.frames[n.substrin
g(p+1)].do
cument; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;
i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.
layers.len
gth;i++) x=MM_findObj(n,d.layers[i]
.document)
;
if(!x && document.getElementById) x=document.getElementById(
n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arg
uments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=
3)
if ((x=MM_findObj(a[i]))!=nul
l){documen
t.MM_sr[j+
+]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</HEAD>
<BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0 text="#003366" link="#990000" vlink="#003366" alink="#003366" background="bkgrnd.jpg" onLoad="MM_preloadImages('
images/for
mat2_02.jp
g','images
/format2_0
4.jpg','im
ages/forma
t2_05.jpg'
,'images/f
ormat2_06.
jpg','imag
es/format2
_07.jpg','
images/for
mat2_08.jp
g','images
/format2_0
9.jpg','im
ages/forma
t2_10.jpg'
,'images/f
ormat2_11.
jpg','imag
es/format2
_12.jpg')"
>
<!-- ImageReady Slices (format.psd) -->
<TABLE WIDTH=700 BORDER=0 CELLPADDING=0 CELLSPACING=0 align="center" bgcolor="#FFFFFF">
<TR>
<TD COLSPAN=2> <IMG SRC="images/format_01.jpg"
ALT="" width="700" height="157"></TD>
</TR>
<TR>
<TD valign="top"><a href="reunion.html" onMouseOut="MM_swapImgRest
ore()" onMouseOver="MM_swapImage(
'Image12',
'','images
/format2_0
2.jpg',1)"
>
</a><a
onMouseOver="MM_swapImage(
'Image12',
'','images
/format2_0
2.jpg',1)"
onMouseOut=MM_swapImgResto
re()
href="
http://www.hhs1980.com/reunion.html"><im
g height=29
src="images/format_02.jpg"
width=193 border=0 name=Image12></a><br>
<a
onMouseOver="MM_swapImage(
'Image13',
'','images
/format2_0
4.jpg',1)"
onMouseOut=MM_swapImgResto
re()
href="
http://www.hhs1980.com/searchalumni.php"
><img height=28
src="images/format_04.jpg"
width=193 border=0 name=Image13></a><br>
<a
onMouseOver="MM_swapImage(
'Image14',
'','images
/format2_0
5.jpg',1)"
onMouseOut=MM_swapImgResto
re()
href="
http://www.hhs1980.com/keyevents.html"><
img height=29
src="images/format_05.jpg"
width=193 border=0 name=Image14></a><br>
<a
onMouseOver="MM_swapImage(
'Image15',
'','images
/format2_0
6.jpg',1)"
onMouseOut=MM_swapImgResto
re()
href="
http://www.hhs1980.com/guestbook.html"><
img height=28
src="images/format_06.jpg"
width=193 border=0 name=Image15></a><br>
<a
onMouseOver="MM_swapImage(
'Image16',
'','images
/format2_0
7.jpg',1)"
onMouseOut=MM_swapImgResto
re()
href="
http://www.hhs1980.com/missing.html"><im
g height=29
src="images/format_07.jpg"
width=193 border=0 name=Image16></a><br>
<a
onMouseOver="MM_swapImage(
'Image17',
'','images
/format2_0
8.jpg',1)"
onMouseOut=MM_swapImgResto
re()
href="
http://www.hhs1980.com/contact.html"><im
g height=29
src="images/format_08.jpg"
width=193 border=0 name=Image17></a><br>
<a
onMouseOver="MM_swapImage(
'Image18',
'','images
/format2_0
9.jpg',1)"
onMouseOut=MM_swapImgResto
re()
href="
http://www.weather.com/weather/local/USAL0287?from=search_city" target="_blank"><img height=28
src="images/format_09.jpg"
width=193 border=0 name=Image18></a><br>
<a
onMouseOver="MM_swapImage(
'Image19',
'','images
/format2_1
0.jpg',1)"
onMouseOut=MM_swapImgResto
re() href="
http://www.hsv.k12.al.us/schools/high/hhs/" target="_blank"><img
height=29 src="images/format_10.jpg"
width=193 border=0
name=Image19></a><br>
<a
onMouseOver="MM_swapImage(
'Image20',
'','images
/format2_1
1.jpg',1)"
onMouseOut=MM_swapImgResto
re()
href="
http://www.hhs1980.com/links.html"><img height=28
src="images/format_11.jpg"
width=193 border=0 name=Image20></a><br>
<a
onMouseOver="MM_swapImage(
'Image21',
'','images
/format2_1
2.jpg',1)"
onMouseOut=MM_swapImgResto
re()
href="
http://www.hhs1980.com/index.html"><img height=71
src="images/format_12.jpg"
width=193 border=0 name=Image21></a></TD>
<TD width="507" valign="top">
<table width="95%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<?
$db = mysql_connect ("localhost", "hhs1980", "harrell") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db("hhs1980_b
ook1",$db)
;
if (($submit == "") || ($submit == "nosubmit"))
{
?>
<td>
<p align="center"><font face="Century Schoolbook"><b>Search for Alumni<br>
Enter search criteria in as many fields as you like.<br>Please report any database problems to <a href=mailto:annasue@comcas
t.net>the Webmaster.</a></b></font><
/p>
<p align="center">
<form method="post" action="searchalumni.php">
<p><span class="style2"><span class="style3"><font face="Century Schoolbook"><b>First Name</b></font></span>:</s
pan>
<input type="text" name="first_name"/>
<br/>
<br>
<span class="style3"><font face="Century Schoolbook"><b>Last Name: </b></font></span>
<input type="text" name="last_name"/>
<br/>
<br>
<span class="style3"><font face="Century Schoolbook"><b>Married Name: </b></font></span>
<input type="text" name="married_name" />
<br/>
<br>
<span class="style3"><font face="Century Schoolbook"><strong>Yearbo
ok information:<br><font face="Century Schoolbook" size=2>In this field, enter any keywords (separated by spaces) as you think might be appropriate such as "Spanish club" (don't include the quotes.)</strong></font></
span></p>
<p> <input type="text" name="keywords" />
<br/>
<br>
</p>
<input type="submit" name="submit" value="Submit" />
</form>
</p>
</td>
</tr>
</table>
<?
}
if ($submit == "Submit")
{
if (($first_name == "") && ($last_name == "") && ($married_name == "") && ($keywords == ""))
{
echo("<center><font face=\"Century Schoolbook\">You must enter search data in at least one field.<br>Please report any database problems to <a href=mailto:annasue@comcas
t.net>the Webmaster.</a>");
}
else
{
?>
<?
if ($first_name !== "")
{
$sql_statement .= "`first_name` LIKE '%$first_name%' && ";
}
if ($last_name !== "")
{
$sql_statement .= "`last_name` LIKE '%$last_name%' && ";
}
if ($married_name !== "")
{
$sql_statement .= "`married_name` LIKE '%$married_name%' && ";
}
if ($keywords !== "")
{
$all_keywords = explode(" ",$keywords);
$count = count($all_keywords);
for ($p = 0; $p <= $count; $p++)
{
if ($all_keywords[$p] != "")
{
//print "$all_keywords[$p] - KEYWORDS<br>";
if ($p != $count)
{
$sql_statement .= "`yearbookinfo` LIKE '%$all_keywords[$p]%' OR ";
}
else
{
$sql_statement .= "`yearbookinfo` LIKE '%$all_keywords[$p]%' && ";
}
}
}
}
$sql_statement = ereg_replace(" && $","",$sql_statement);
$sql_statement = ereg_replace(" OR $","",$sql_statement);
$sql_statement = str_replace("\" ","\"",$sql_statement);
// $sql_statement_to_run = "Select * from `hhsreunion` WHERE 'first_name' LIKE '%zzz%' ";
$sql_statement_to_run = "Select * from `hhsreunion` WHERE $sql_statement ";
print "$sql_statement_to_run = STATEMENT<br>";
$result_seniors = mysql_query($sql_statement
_to_run);
if (!$result_seniors) {
die('Your search did not yield any return from the database.<br>Click <a href=searchalumni.php?subm
it=nosubmi
t>here</a>
to return to the search page.</font><br></center> ' .
mysql_error());
}
else
{
?>
<td>
<p align="center"><font face="Century Schoolbook"><b>Results of Search<br>Click on a photo to see more details.<br>Please report any database problems to <a href=mailto:annasue@comcas
t.net>the Webmaster.</a><br><font color=red>Missing</font> means we cannot locate the senior; if you have any information, please email it to <a href=mailto:S15diane@yahoo
.com>S15di
ane@yahoo.
com</a>.</
b></font><
/p>
<p align="center">
<p>
<table align="center" border=1>
<?
$num_rows = mysql_num_rows($result_sen
iors);
if ($num_rows != 0)
{
while ($line = mysql_fetch_row($result_se
niors))
{
foreach ($line as $col_value)
{
$first_name = $line[0];
$last_name = $line[1];
$married_name = $line[2];
if ($married_name == "")
{
$married_name = " ";
}
$status = $line[3];
if ($address == "")
{
$status = " ";
}
if ($status == "M")
{
$status = "<br><font color=red>Missing</font>";
}
if ($status == "D")
{
$status = "<br><font color=red>Deceased</font>"
;
}
$address = $line[4];
if ($address == "")
{
$address = " ";
}
$email = $line[5];
if ($email == "")
{
$email = " ";
}
$yearbookinfo = $line[6];
$yearbookphoto = $line[7];
$currentinfo = $line[8];
if ($currentinfo == "")
{
$currentinfo = " ";
}
$newphoto = $line[9];
if ($newphoto == "")
{
$newphoto = " ";
}
?>
<tr>
<td align=center><font size=2 face=Arial><b><u>First Name</td>
<td align=center><font size=2 face=Arial><b><u>Last Name</td>
<td align=center><font size=2 face=Arial><b><u>Married Name</td>
<td align=center><font size=2 face=Arial><b><u>Yearbook Photo</td>
</tr>
<tr>
<td align=center><font face="Verdana, Arial, Helvetica, sans-serif" size=2><b>
<?php echo $first_name ?><?php echo $status ?></b></font>
<td align=center><font face="Verdana, Arial, Helvetica, sans-serif" size=2><b>
<?php echo $last_name ?></font>
<td align=center><font face="Verdana, Arial, Helvetica, sans-serif" size=2><b>
<?php echo $married_name ?></font>
<td align=center><font face="Verdana, Arial, Helvetica, sans-serif" size=2><a href="individual.php?first
_name=<? echo $first_name ?>&last_name=<? echo $last_name ?>"><img src="photos/<?php echo $yearbookphoto ?>"</a></font>
</tr>
<?
break;
}
}
?>
<?php
}
}
}
}
?>
</table>
<center>Click <a href=searchalumni.php?subm
it=nosubmi
t>here</a>
to return to the search page.</font><br></center>
<P align=center><FONT face="Century Schoolbook" color=#ff0000 size=5>1980
- the Class with Class!!!</FONT></P>
<P align=center><FONT face="Century Schoolbook" color=#ff0000
size=4><B><FONT size=5>GO BIG RED!!!</FONT></B></FONT></
P>
<P align=center><IMG height=23 src="hrline.jpg"
width=507></P>
</TD>
</TR>
</TABLE>
<!-- End ImageReady Slices -->
</BODY>
</HTML>