fongfuse
fongfuse

Reputation: 129

How to insert many data in one column

How to insert many data in one column

example

user_log(primary key)         favorite
--------                       ----
       a                       car
       b                       cat
       c                       dog

and I want to insert data in favorite

this bottom is I want.

user_log(primary key)          favorite
--------                       ----
       a                       car
       c                       dog
       a                       home
       a                       swimming

I try INSERT INTO userss (user_log,fav) values ('".$_POST["key"]."','".$_POST["fav"]."')

this is error Duplicate entry '..' for key 'PRIMARY'

Upvotes: 1

Views: 91

Answers (3)

Abhishek Tiwari
Abhishek Tiwari

Reputation: 33

It seems same entry key "a". You just have to remove this column as primary key. It can't be same and should be unique.

Upvotes: 1

Kaushik solanki
Kaushik solanki

Reputation: 438

A primary key does not allow for duplicate keys.

Change your Table structure to store data as per your requirement.

Remove Primary key from user_log and add one more columns name id(as per your requirement) with primary key.

After, run your script.. it's work for you.

You can do same as this.

Hope u got it :) Enjoy :)

Upvotes: 2

user247217
user247217

Reputation: 394

Try like below i hope its solve you problem.

id(primary key)   user_log                  favorite
                   --------                  ----
 1                   a                       car
 2                   c                       dog
 3                   a                       home
 4                   a                       swimming

Upvotes: 1

Related Questions