Prevent duplication when inserting

Discuss MySQL Ajax Table Editor

Prevent duplication when inserting

Postby buconet » Fri Jul 17, 2020 11:59 pm

Hello everyone, does anyone know how I can validate that a record is not repeated in the database, that is, I have a table called employees but the email field must be unique, as I use in version 4.2 of mate to validate before inserting?

I would really appreciate it if you could help me with it
buconet
 
Posts: 28
Joined: Thu May 15, 2014 8:32 pm

Re: Prevent duplication when inserting

Postby buconet » Sat Jul 18, 2020 4:40 pm

Solved!!! :D
buconet
 
Posts: 28
Joined: Thu May 15, 2014 8:32 pm

Re: Prevent duplication when inserting

Postby MikeW » Thu Nov 26, 2020 9:22 pm

Here my solution:

Code: Select all
function validateFun($col,$val,$row)
   {

   // Ist user_name bereits vorhanden ?
      $query = "select user_name from users where user_name = :id";
         $queryParams = array('id' => $val);
         $stmt = DBC::get()->prepare($query);
         $stmt->execute($queryParams);
         $count = $stmt->rowCount();

      if ($count == 0)
      {
         return true;
      }
      else
      {
         $this->Editor->retArr[] = array('where' => 'javascript', 'value' => 'alert("Sorry this value already exists in the db");');
         return false;
      }
   }
MikeW
 
Posts: 27
Joined: Mon Oct 31, 2011 11:43 am


Return to Open Discussion

Who is online

Users browsing this forum: No registered users and 8 guests

cron