Question

Locked

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.

3 total posts (Page 1 of 1)  
| 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
registeration.<br/>

public function usernameExists($username)<br/>

{<br/>


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


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

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


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

{<br/>

return false;<br/>

}<br/>


return true;<br/>

}<br/>


this will give 0 or 1<br/>


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


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


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

{<br/>

echo "username exist";<br/>


}<br/>

else<br/>

{<br/>

//proceed<br/>

}<br/>

Back to Web Development Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums