Solved

die message if query unsuccessful...

Posted on 2004-08-10
3
278 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php output utf-8 problem 6 52
Horizontal Full Calendar using php 5 44
Conditional Array Element 7 28
replacate wordpress websites 3 24
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
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.

751 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