Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

die message if query unsuccessful...

Posted on 2004-08-10
3
Medium Priority
?
299 Views
Last Modified: 2006-11-17
Hi,
The following is a query to see if a database record matches $sender_email....works fine, but I can't seem to get the 'die' bit to work. i.e. if someone's entered an email which doesn't exist in the records, it doesn't seem to display 'Your record doesn't exist'...

$result=mysql_query("SELECT * FROM members where mem_email='$sender_email'") or die("Your Record does not exist" . mysql_error());
0
Comment
Question by:skylabel
3 Comments
 
LVL 10

Assisted Solution

by:ThaSmartUno
ThaSmartUno earned 1000 total points
ID: 11769345
0
 
LVL 5

Accepted Solution

by:
winglis4 earned 1000 total points
ID: 11769512
Actually, I believe you are testing for this at the wrong time.

This is from php.net reference on the mysql_query statement.
  Only for SELECT,SHOW,EXPLAIN or DESCRIBE statements mysql_query()  returns a resource identifier or FALSE if the query was not executed correctly. For other type of SQL statements, mysql_query() returns TRUE on success and FALSE on error. A non-FALSE return value means that the query was legal and could be executed by the server. It does not indicate anything about the number of rows affected or returned. It is perfectly possible for a query to succeed but affect no rows or return no rows.

You should add your error checking afterwards, with a mysql_num_rows call, or the like.

This is not tested, but I think it should at least point you in the right direction.

$result=mysql_query("SELECT * FROM members where mem_email='$sender_email'");
$numrows = mysql_num_rows($result);
if ($numrows < 1)
   {echo "Your Record does not exist";
    exit;  
}

Good luck!
0
 
LVL 1

Author Comment

by:skylabel
ID: 11769729
thank you ...thank you.....
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question