Duplicate entry '0' for key 'PRIMARY'
17 replies [Last post]
does not have a status.
User offline. Last seen 2 days 22 hours ago. Offline
Joined: 08/16/2009
Points: 57

Duplicate entry '0' for key 'PRIMARY'...apa pandangan anda tentang error nie..lepas saya buat kemaskini dan kembali ke page papar..terus keluar error nie..

newbie
User offline. Last seen 4 days 12 hours ago. Offline
Joined: 12/09/2009
Points: 234

aku rase ade primary key yang value = 0 dalam table dan script cuba nk INSERT row baru dengan primary key = 0

does not have a status.
User offline. Last seen 2 days 22 hours ago. Offline
Joined: 08/16/2009
Points: 57

tiba2 je wujud primary key=0.

betul tu, memang ada primary key=0.

dah buat autoincrement..

newbie
User offline. Last seen 4 days 12 hours ago. Offline
Joined: 12/09/2009
Points: 234

ade la tuh silap kat mane2. selain auto increment, aku suggest letak attributes = unsigned. kalu camtu, nombor negative x dibenarkan.

keje :)
zam3858's picture
User offline. Last seen 5 days 20 hours ago. Offline
Moderator
Joined: 04/26/2003
Points: 265

autoincrement tu tak bermakna kita tak leh assign satu nilai untuk dia. autoincrement akan assign nilai kalo kita tak letak. kalau value tu still unique, dia akan simpan dengan happynya.

does not have a status.
User offline. Last seen 2 days 22 hours ago. Offline
Joined: 08/16/2009
Points: 57

tetapi, nilai unique dah assign,,,,,selepas update...nilai unique tersebut diganti dgn nilai 0..dahsyat..design table saya silap ke?

newbie
User offline. Last seen 4 days 12 hours ago. Offline
Joined: 12/09/2009
Points: 234

cikya assign attribute auto increment sblm atau selepas mslh ni timbul?

busy man
User offline. Last seen 7 hours 50 min ago. Offline
Joined: 08/08/2004
Points: 294

ada buat insert ignore atau update ignore ?

does not have a status.
User offline. Last seen 2 days 22 hours ago. Offline
Joined: 08/16/2009
Points: 57

assign attribute auto increment sblm ..masalah nie timbul.

does not have a status.
User offline. Last seen 2 days 22 hours ago. Offline
Joined: 08/16/2009
Points: 57

ada buat insert ignore atau update ignore?

x tahu pula pasal ignore nie..

does not have a status.
User offline. Last seen 9 weeks 4 days ago. Offline
Joined: 01/27/2010
Points: 28

hmm... pasal primary key ni...

1. masa insert data, make sure primary key (normally ID) tak yah insert
contohnya: insert into <table> (name, email) values ($name, $email)

2. kalau dia ada insert 0, ko drop field:ID, pastu create new primary key with auto_increment,

contohnya:

create table people (
  id int not null auto_increment,
  name varchar(25) not null,
  email varchar(64) not null,
  primary key (id)
);

3. try drop field guna phpMyAdmin pastu add new field ID auto_increment

does not have a status.
User offline. Last seen 2 days 22 hours ago. Offline
Joined: 08/16/2009
Points: 57

OK....

keje :)
zam3858's picture
User offline. Last seen 5 days 20 hours ago. Offline
Moderator
Joined: 04/26/2003
Points: 265

uih.. jgn buat camtu. karang apa jadik ngan id2 yg dah ada?

tanya diri... apsal ada application tu cuba untuk insert dengan data id=0. simple je... sebab ko specify field id dalam insert statement tu. atau update statement ko tak dapat value id yg betul.

so sebenarnya problem kat coding. print statement sql tu before ko run, tengok ada tak supply value id yg betul. fix coding tu dulu.

does not have a status.
User offline. Last seen 9 weeks 4 days ago. Offline
Joined: 01/27/2010
Points: 28

hehehe... betul juga cakap zam... tapi kalau ID tu takde refer ke table2 yang lain.. then ok laa kolo ndak drop pastu create new id...

does not have a status.
User offline. Last seen 2 days 22 hours ago. Offline
Joined: 08/16/2009
Points: 57

owhh..dah delete dah ID tu, dah buat mcm azrad suruh..

does not have a status.
User offline. Last seen 9 weeks 4 days ago. Offline
Joined: 01/27/2010
Points: 28

huhuhu... harap2 takde table yang affected bila guna new ID ni nanti...

*rasa bersalah plak aku... Evil

keje :)
zam3858's picture
User offline. Last seen 5 days 20 hours ago. Offline
Moderator
Joined: 04/26/2003
Points: 265

cikya belajar benda baru dalam PHP ari ni. Object Oriented Programming Style

atau singkatannya... OOPS!

does not have a status.
User offline. Last seen 2 days 22 hours ago. Offline
Joined: 08/16/2009
Points: 57

terima kasih kawan2 ku dgn segala tunjuk ajar..

OOPs...alhamdulillah ..dah faham sikit.dah ok.. Smile