Web Development

Our forums are currently in maintenance mode and the ability to post is disabled. We will be back up and running as soon as possible. Thanks for your patience!



Validating duplicate db records with PHP

By giantsand98 ·
I have an account profile update page that I would like to turn off PHP error reporting on and instead catch unique value constraint errors in a user friendly fasion using PHP instead.

Is there a way to capture PHP errors (even with them turned off at runtime) and use them to decide what custom error messages to display to the user?

Any other suggestions would be appreciated as well.

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

If you mean

by Tony Hopkinson In reply to Validating duplicate db r ...

you want to trap primary key violations.
The execute method is a function, if there's an error it will return something to indicate there has been one and what sort it is.

srvesponse = mysqlcommand.execute;
or some such and then test for those3 errors you can deal with.

It's not a PHP error, it's a database one.

Collapse -

U can try it from back end

by ahamedjais In reply to Validating duplicate db r ...

try to excute a query which returns a boolean
for eg:To check username dulipcation on

public function usernameExists($username)<br/>


$sql =
COUNT(user.user_name) AS userExists
user.user_name = '".$username."'";<br/>

$exe = mysql_query($sql);<br/>

$rs =mysql_fetch_array($exe);<br/>

if ($rs['userExists'] <= 0)<br/>


return false;<br/>


return true;<br/>


this will give 0 or 1<br/>

<b>then call above fuction</b><br/>

$result = $this->usernameExists($username);<br/>

if($result == 1)<br/>


echo "username exist";<br/>






Related Discussions

Related Forums