Question Locked

Validating duplicate db records with PHP

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

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.

3 replies

by tony hopkinson

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.

by ahamedjais

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

public function usernameExists($username)

{

$sql =
"SELECT
COUNT(user.user_name) AS userExists
FROM
user
WHERE
user.user_name = '".$username."'";

$exe = mysql_query($sql);

$rs =mysql_fetch_array($exe);

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

{

return false;

}

return true;

}

this will give 0 or 1

then call above fuction

$result = $this->usernameExists($username);

if($result == 1)

{

echo "username exist";

}

else

{

//proceed

}

This discussion is closed to new replies.