php - $wpdb->insert is not respacting unique fields -


i have been creating wordpress plugin while. example of mysql table:

$sql = "create table if not exists $table_name  (     id int(11) not null auto_increment,     email       varchar(100) default null,     telephone   varchar(15) default null,     primary key(id),     unique (email, telephone)     ) engine=innodb default charset=utf8 comment='wp plugin sesa_players db' auto_increment=1 ; "; 

email should unique, right? phpmyadmin says it.

this wordpress code inserts data table:

$err = $wpdb->insert($wpdb->prefix.$table_name, $data, $format); var_dump($err); 

it works, more should. assume email m@m.com. first insert goes well. second try fails because of duplicate entry should. var_dump false.
if refresh wp page, third try same email passes flawlessly, var_dump 1. repeated wp refresh opens db duplicate entry. why? doing wrong?

no, email not unique here. pair of email , telephone unique in table definition.

$sql = "create table if not exists $table_name  (     id int(11) not null auto_increment,     email       varchar(100) default null,     telephone   varchar(15) default null,     primary key(id),     unique (email),     unique (telephone)     ) engine=innodb default charset=utf8 comment='wp plugin sesa_players db' auto_increment=1 ; "; 

probably want.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -