Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Custom error message for SQL
Old 07-07-2010, 11:25 AM Custom error message for SQL
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
Neat little thing to customize the error messages. I know this is easy to all you pros, but this may not be so easy for a newcomer.

PHP Code:
$SQLErr "Duplicate entry 'NAME' for key 'PRIMARY'";
    if (
mysql_error()==$SQLErr) {
      echo 
"<p>Sorry, but that username is taken.  Please choose a different one.</p>";
    } 
Just change $SQLErr to be what your error message is, and change the echo inside the if to be your custom error message!
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is online now
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-07-2010, 01:01 PM Re: Custom error message for SQL
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
I always test for a match before trying to insert a record rather that letting the DB server/client raise an error.

However instead of trying to match the error text check the error number and if if it > 0 send a suitable message.

http://www.php.net/manual/en/function.mysql-errno.php
http://dev.mysql.com/doc/refman/5.1/...-handling.html
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Custom error message for SQL
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.09752 seconds with 12 queries