Solved

die message if query unsuccessful...

Posted on 2004-08-10
3
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

623 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