Link to home
Start Free TrialLog in
Avatar of livegirllove
livegirllove

asked on

Return Message if id number not found

How do I tell php/mysql to return a different message if the id number entered is not in the table?  Here is the script I'm using:            

<form action="" method="POST">
              <input type="text" name="serviceid" >
              <input type="submit" name="submit" value="Get Your Drivers">
              <input type="hidden" name="submit" value="Submit Service Tag Number">
            </form>
          <p class="newsbody">&nbsp;</p></td>
          <td width="55%" class="contactform"><div align="center">              <img src="../images/servicecodepic1.jpg" width="320" height="240"><br>
          <span class="google">(usually located on the bottom of your computer)</span></div></td>
        </tr>
      </table>      
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <?php
        if (!empty($_POST)) { // form is subitted
include("db.php"); // setup connection to mysql
$sql = "SELECT drivers.id, drivers.name, drivers.link, drivers.cat FROM servicetag, drivers WHERE servicetag.id='$serviceid' AND drivers.id IN(servicetag.mb, servicetag.vid, servicetag.lan, servicetag.sound, servicetag.modem, servicetag.scsi, servicetag.other1, servicetag.other2, servicetag.other3, servicetag.other4)";
$res_cat = mysql_query($sql) or die(mysql_error()); // handle to category set
print "<table><tr><th>Here Are Your Drivers and any Software Packages that came with your <br>";
print "Custom SOLOHelp.com Computer</th></tr>";
while($row = mysql_fetch_assoc($res_cat)) { // fetch the row
print "<tr><td>\n<p><a href=\"{$row['link']}\">{$row['name']}</a></p>\n</td></tr>\n";
}
print "</table>";
}
?>
Avatar of ThaSmartUno
ThaSmartUno

add before $res_cat = mysql_query($sql) or die(mysql_error()); // handle to category set

if (mysql_num_rows($res_cat) < 1) {
   echo "no category.";
} else {
   // continue with the rest.

}
SOLUTION
Avatar of Marcus Bointon
Marcus Bointon
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of livegirllove

ASKER

thasmartuno- your solution gives this error on any query.
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /hsphere/local/home/soloente/support.solohelp.com/index.php on line 114
no category.
Here is the code:
      <?php
        if (!empty($_POST)) { // form is subitted
include("db.php"); // setup connection to mysql
$sql = "SELECT drivers.id, drivers.name, drivers.link, drivers.cat FROM servicetag, drivers WHERE servicetag.id='$serviceid' AND drivers.id IN(servicetag.mb, servicetag.vid, servicetag.lan, servicetag.sound, servicetag.modem, servicetag.scsi, servicetag.other1, servicetag.other2, servicetag.other3, servicetag.other4)";
if (mysql_num_rows($res_cat) < 1) {
   echo "no category.";
} else {
   // continue with the rest.


$res_cat = mysql_query($sql) or die(mysql_error()); // handle to category set
print "<table><tr><th>Here Are Your Drivers and any Software Packages that came with your <br>";
print "Custom SOLOHelp.com Computer</th></tr>";
while($row = mysql_fetch_assoc($res_cat)) { // fetch the row
print "<tr><td>\n<p><a href=\"{$row['link']}\">{$row['name']}</a></p>\n</td></tr>\n";
}
print "</table>";
}
}

?>
***************************************************************************

Squinky-
Long time no see ;-)

Parse error: parse error in /hsphere/local/home/soloente/support.solohelp.com/index.php on line 149
Line 149 is the last line in the page.  </html>
      <?php
        if (!empty($_POST)) { // form is subitted
include("db.php"); // setup connection to mysql
$sql = "SELECT drivers.id, drivers.name, drivers.link, drivers.cat FROM servicetag, drivers WHERE servicetag.id='$serviceid' AND drivers.id IN(servicetag.mb, servicetag.vid, servicetag.lan, servicetag.sound, servicetag.modem, servicetag.scsi, servicetag.other1, servicetag.other2, servicetag.other3, servicetag.other4)";
$res_cat = mysql_query($sql) or die(mysql_error()); // handle to category set
if (mysql_num_rows($res_cat) >= 1) {
print "<table><tr><th>Here Are Your Drivers and any Software Packages that came with your <br>";
print "Custom SOLOHelp.com Computer</th></tr>";
while($row = mysql_fetch_assoc($res_cat)) { // fetch the row
print "<tr><td>\n<p><a href=\"{$row['link']}\">{$row['name']}</a></p>\n</td></tr>\n";
}
print "</table>";
} else {
print "<p>no drivers found for service tag $serviceid</p>\n";
}?>


ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks for the help.

For anyone that sees this later.....          

 <form action="index.php#anch" method="POST">
              <input type="text" name="serviceid" >
              <input type="submit" name="submit" value="Get Your Drivers">
              <input type="hidden" name="submit" value="Submit Service Tag Number">
            </form>
          <p class="newsbody">&nbsp;</p></td>
          <td width="55%" valign="top" class="contactform"><div align="center"><a name="anch"></a><img src="http://www.soloenterprises.org/images/servicecodepic1.jpg" width="320" height="240"><br>
              <span class="google">(usually located on the bottom of your computer)</span></div></td>
        </tr>
      </table>      
<?php
       if (!empty($_POST)) { // form is subitted
include("db.php"); // setup connection to mysql
$sql = "SELECT drivers.id, drivers.name, drivers.link, drivers.cat FROM servicetag, drivers WHERE servicetag.id='$serviceid' AND drivers.id IN(servicetag.mb, servicetag.vid, servicetag.lan, servicetag.sound, servicetag.modem, servicetag.scsi, servicetag.other1, servicetag.other2, servicetag.other3, servicetag.other4)";
$res_cat = mysql_query($sql) or die(mysql_error()); // handle to category set
if (mysql_num_rows($res_cat) < 1) {
   echo "<h3>Sorry <font color=\"red\">$serviceid</font> Could Not Be Found. <br> Please Check the Service Code and Try Again<br>If that fails Please call ****** 5536</h3>";
} else {
   // continue with the rest.


print "<table><tr><td width=\"50%\" valign=\"top\"><h3>Here Are Your Drivers and any Software Packages that came with your <br>";
print "Custom SOLOHelp.com Computer</h3></td><td>";
while($row = mysql_fetch_assoc($res_cat)) { // fetch the row
print "<p class=\"newsbody\"><a href=\"{$row['link']}\">{$row['name']}</a><br>";
}
print "</p></td></tr></table>";
}
}

?></td>