PHP script to prevent two equal data from being entered (Mysql)

Asked

Viewed 266 times

0

I am developing a system for my school’s library and would like to know how to make a script in PHP, with Mysql database, which, at the time of registration, check if there is a record with that CPF.

  • 1

    Easier and safer to place the field of CPF as UNIQUE, this way the database will not allow repeated values and will return an error while trying.

  • Right, but how can I customize this error, like; "This number has already been registered."

  • These errors have a código and a mensagem default. You can force the error and catch the código returned, having it, just do a validation for when the error has this código, return the desired message.

  • Understood, but you can give me an example (with code)?

  • Later I put, I’m not in time to make the code. You’re using MySQLi or PDO ?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.