Re: IF's!

From: Date: Wed, 26 Sep 2007 18:38:39 +0000
Subject: Re: IF's!
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-262487@lists.php.net to get a copy of this message
On 9/26/07, Dan Shirah <mrsquash2@gmail.com> wrote: > Okay, I know this is probably a real easy fix, and I could swear I've done > it before, but for some reason it's just not working. > > Below is my query, it does a conditional search based on info put in a form > by the user. If I put in a valid letter/name for the last_name that I know > is in my database everything works fine. > > BUT, if I put in a character/name for the last_name that does not exist in > my database I get the following error: Call to undefined function > mssql_error() when I should be getting the echo, "No results" > > The snipet of my code that is throwing the error is: > if (!empty($tot_result)) { > $total_results = mssql_num_rows($tot_result) or die(mssql_error()); > } > > Should I not use (!empty()) when checking to see if a query did not return > any results? > > MY CODE: > <?php > // Figure out the total number of results in DB: > $sql_total= "SELECT * FROM payment_request WHERE payment_request.status_code > = 'P'"; > if ($customer_last != "") { > $sql_total.=" AND last_name LIKE '$customer_last%'"; > if ($customer_first != "") { > $sql_total.=" AND first_name LIKE '$customer_first%'"; > } > } > $tot_result = mssql_query($sql_total) or die(mssql_error()); > if (empty($tot_result)) { > echo "No results"; > } > if (!empty($tot_result)) { > $total_results = mssql_num_rows($tot_result) or die(mssql_error()); > } > // Figure out the total number of pages. Always round up using ceil() > $total_pages = ceil($total_results / $max_results); > //echo "Results per page: ".$max_results."\n <br />"; > //echo "Total results: ".$total_results."\n <br />"; > //echo "Total number of pages needed: ".$total_pages."\n <br />"; > ?> > Dan, Your syntax is correct, but mssql_error() doesn't exist in PHP to my knowledge. Try replacing that with mssql_get_last_message(); (sans quotes, of course) and see if that fixes the problem. -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107 Give a man a fish, he'll eat for a day. Then you'll find out he was allergic and is hospitalized. See? No good deed goes unpunished....

« previous php.general (#262487) next »