Solved

die message if query unsuccessful...

Posted on 2004-08-10
3
261 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 250 total points
ID: 11769345
0
 
LVL 5

Accepted Solution

by:
winglis4 earned 250 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now