php - MYSQL Duplicate rows -


i trying insert values table in mysql, table has column should unique,so column have different values.

i tried putting unique coloumn did not work, tried putting column primary key , insert ignore into command did not work (http://www.tutorialspoint.com/mysql/mysql-handling-duplicates.htm)

my intention put phonenumber column unique every value in column different. if newly inserting value not unique should skip wihout giving error.

my code create table:

  public function create_member_table($table)  { $this->sql ="create table if not exists $table ( id bigint not null auto_increment,                                     username varchar(50) not null,                                     phonenumber varchar(20) not null,                                     country varchar(2) not null,                                     profession varchar(5000) not null,                                     profilepic varchar(5000) not null,                                     smskey varchar(100) not null,                                     status int not null,                                     reg_date_time datetime not null,                                     unique (id,phonenumber))                                     partition hash(id)                                     partitions 1023;"; $this->tb = mysqli_query($this->ret,$this->sql); if(!$this->tb){   echo "table not created<br>";  } else{   echo "table created<br>";  } 

insert table:

  public function table_member_insert($table,$phonenumber="",$username="",$country="",$profession="",$profilepic="0",$smskey="",$status="") {     $this->sql = "insert $table                   (username,phonenumber,country,profession,profilepic,smskey,status,reg_date_time)                   values                   ('$username','$phonenumber','$country','$profession','$profilepic','$smskey','$status',now());";                    $this->tb = mysqli_query($this->ret,$this->sql);                   if(!$this->tb){                     echo "values not inserted<br>";                    }                   else{                     echo "values inserted<br>";                   } } 

the problem defined combination of id , phonenumber fields unique. since id field defined auto_increment, unique on own, therefore combination phonenumber field unique.

you need define phonenumber field alone unique. after can use insert ignore insert new record existing phone number without raisin error. however, pls note in case of match, unique index prevent entire record being inserted.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -