Bootstrap FreeKB - PHP - Prevent duplicate entries into MySQL
PHP - Prevent duplicate entries into MySQL

Updated:   |  PHP articles

When using PHP to insert records into our MySQL table, if / else statements can be used to prevent duplicate entries from being entered.  For this tutorial, let's say we are using inserting error codes into our MySQL table.  We will assume there is already a record in MySQL with error code ERR134.  The following code will display an error if we try to insert ERR134 into MySQL.

$data_being_entered = $GET['data'];
$insert = "insert into tablename $data_being_entered";

if($data_being_entered == 'ERR134') {echo 'There is already a record in MySQL with error message ERR134';}
else{$insert};




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


June 25 2022 by sadsadsasdsd


Add a Comment


Please enter a836bd in the box below so that we can be sure you are a human.