One additional point to clarify: the @ sign in front of the mysql_query
_suppresses any error/warning that may be generated by PHP.  It can be
useful on many occasions in PHP (the example that usually springs to my mind
it opening files, to ensure that a warning is not displayed if the file
couldn't be opened).

Ross

> -----Original Message-----
> From: Christian Leberfinger [mailto:[EMAIL PROTECTED]]
> Sent: 21 June 2002 06:58
> To: Jack; [EMAIL PROTECTED]
> Subject: RE: [PHP-WIN] How to Show my Own Error Message Instead of Mysql
> Error?
>
>
> Here is a simple solution.
>
> if (!($SQLresult = @mysql_query($SQLquery, $DBresource)))
> {
>       echo "Errormessage...";
>
> } //endif
>
>
> Of course you could also check the Errortype [mysql_errno()]
> to be sure, whether it is a duplicate-key-errror.
>
> The cleanest solution is to use an ID-key, such as:
>
> ID, Username, Name, Adress, ..., Somefield
>
> Then, of course you have to check on existing users.
>
> You have to be careful to handle two equal requests
> posted at the same time!
> Martin Towell's code might fail when the same insert-
> request is executed just after he has queried the count(*)
> and before PHP is inserting.
>
> Then PHP thinks, the user doesn't exist [count(*)== 0] and
> the insert fails because of duplicate keys.
>
> -> always check the mysql_error
>
>
> Regards,
>
>
>
> Christian Leberfinger
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to