[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

Php script not testing correctly for no return from database query.

Asked by annasue in PHP and Databases

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.oSrc;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_preloadImages.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&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; 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.length;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.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.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/format2_02.jpg','images/format2_04.jpg','images/format2_05.jpg','images/format2_06.jpg','images/format2_07.jpg','images/format2_08.jpg','images/format2_09.jpg','images/format2_10.jpg','images/format2_11.jpg','images/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_swapImgRestore()" onMouseOver="MM_swapImage('Image12','','images/format2_02.jpg',1)">
      </a><a
      onMouseOver="MM_swapImage('Image12','','images/format2_02.jpg',1)"
      onMouseOut=MM_swapImgRestore()
      href="http://www.hhs1980.com/reunion.html"><img height=29
      src="images/format_02.jpg" width=193 border=0 name=Image12></a><br>
      <a
      onMouseOver="MM_swapImage('Image13','','images/format2_04.jpg',1)"
      onMouseOut=MM_swapImgRestore()
      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_05.jpg',1)"
      onMouseOut=MM_swapImgRestore()
      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_06.jpg',1)"
      onMouseOut=MM_swapImgRestore()
      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_07.jpg',1)"
      onMouseOut=MM_swapImgRestore()
      href="http://www.hhs1980.com/missing.html"><img height=29
      src="images/format_07.jpg" width=193 border=0 name=Image16></a><br>
      <a
      onMouseOver="MM_swapImage('Image17','','images/format2_08.jpg',1)"
      onMouseOut=MM_swapImgRestore()
      href="http://www.hhs1980.com/contact.html"><img height=29
      src="images/format_08.jpg" width=193 border=0 name=Image17></a><br>
      <a
      onMouseOver="MM_swapImage('Image18','','images/format2_09.jpg',1)"
      onMouseOut=MM_swapImgRestore()
      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_10.jpg',1)"
      onMouseOut=MM_swapImgRestore() 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_11.jpg',1)"
      onMouseOut=MM_swapImgRestore()
      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_12.jpg',1)"
      onMouseOut=MM_swapImgRestore()
      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_book1",$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@comcast.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>:</span>    
    <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>Yearbook 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@comcast.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?submit=nosubmit>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@comcast.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>S15diane@yahoo.com</a>.</b></font></p>
            <p align="center">
<p>
<table align="center" border=1>

<?
      $num_rows = mysql_num_rows($result_seniors);
      if ($num_rows != 0)
      {
            while ($line = mysql_fetch_row($result_seniors))
            {
                  foreach ($line as $col_value)
                     {
                     $first_name = $line[0];
                     $last_name = $line[1];
                     $married_name = $line[2];
                           if ($married_name == "")
                           {
                                 $married_name = "&nbsp;";
                           }
                     $status = $line[3];
                           if ($address == "")
                           {
                                 $status = "&nbsp;";
                           }
                           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 = "&nbsp;";
                           }
                     $email = $line[5];
                           if ($email == "")
                           {
                                 $email = "&nbsp;";
                           }
                     $yearbookinfo = $line[6];
                     $yearbookphoto = $line[7];
                     $currentinfo = $line[8];
                           if ($currentinfo == "")
                           {
                                 $currentinfo = "&nbsp;";
                           }
                     $newphoto = $line[9];
                           if ($newphoto == "")
                           {
                                 $newphoto = "&nbsp;";
                           }
?>
<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?submit=nosubmit>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>
[+][-]09/05/05 08:17 AM, ID: 14823929Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: PHP and Databases
Sign Up Now!
Solution Provided By: WoodyRoundUp
Participating Experts: 2
Solution Grade: A
 
[+][-]09/05/05 11:24 PM, ID: 14827005Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]02/08/06 02:18 AM, ID: 15900960Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]02/12/06 10:57 AM, ID: 15935935Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92