preventing duplicate row insertion in php/mysql

后端 未结 3 1247
生来不讨喜
生来不讨喜 2020-12-20 17:22

how do you prevent the entry of duplicate records in php mysql? validating input before insertion to the table.

i am currently building a user registration section f

3条回答
  •  旧时难觅i
    2020-12-20 18:02

    i used the sql statement along with an if else statement.

    mysql_select_db($database_speedycms, $speedycms);
    $query_usercheck = "SELECT * FROM tbl_users WHERE username='$user' OR email='$email'";
    $usercheck = mysql_query($query_usercheck, $speedycms) or die(mysql_error());
    $row_usercheck = mysql_fetch_assoc($usercheck);
    $totalRows_usercheck = mysql_num_rows($usercheck);
    

    then

    if ( $totalRows_usercheck > 0 )
    

    display an error message to prevent any duplicates from being added

    otherwise allow database insert

提交回复
热议问题