MySQL error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
exentric
Forum Newbie
Posts: 5
Joined: Mon Mar 08, 2010 12:14 am

MySQL error

Post by exentric »

Hi..

I receive an error when my program tries to insert duplicate entry into the table.. I don't want my user to get scared on seeing the error.. I want to display it in a different way.. Could any one please help me how I can do that?

I tried using 'die' but no change..

Thanks for your assistance...
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: MySQL error

Post by jraede »

What does your code look like? Do you have "...or die(mysql_error())" after the query?
exentric
Forum Newbie
Posts: 5
Joined: Mon Mar 08, 2010 12:14 am

Re: MySQL error

Post by exentric »

Hi jraede,

yes.. I gave like this..

$query4="insert into ...";
$result4=query($CDBC, $query4) or die(mysql_error());

But it didn't change anything...

Thanks for your help..
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: MySQL error

Post by jraede »

Well, the mysql_error() function displays the error that you don't want users to see. Instead, you can change it to ...or die('You are trying to insert a duplicate value.'); However, just be aware that this will display whenever you get ANY MySQL error, even if it's not from a duplicate query. But, if all of your syntax is correct, the only error you should be getting is if it's a duplicate value, so you should be ok.
exentric
Forum Newbie
Posts: 5
Joined: Mon Mar 08, 2010 12:14 am

Re: MySQL error

Post by exentric »

.. I tried that also.. but the error page remains the same.. nothing gets changed

$result4=query($CDBC, $query4) or die('You are trying to inserta duplicate value.');

I am new to this.. Let me ask another doubt related to this please.. if I am giving mysql_error(), then will the error number be displayed in the error page ( I think it should right? ) ... But I am not seeing any error number getting displayed in the error page..
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: MySQL error

Post by jraede »

Are you sure the error you're getting is a MySQL error and not a PHP error? What is the exact error you are getting?
exentric
Forum Newbie
Posts: 5
Joined: Mon Mar 08, 2010 12:14 am

Re: MySQL error

Post by exentric »

Please find the error below:
"

You are linking Paul OwensERROR with QUERY:
insert into ....

MYSQL ERROR:

Duplicate entry '155-1-2-3' for key 1

"

I just removed the 'insert' code.. :).. In the error page it will show me the complete insert statement..

Thanks for all your help...
exentric
Forum Newbie
Posts: 5
Joined: Mon Mar 08, 2010 12:14 am

Re: MySQL error

Post by exentric »

I hope someone could help me with this issue.. :)

Thanks..
Post Reply