Jump to content


Photo

INSERT problems


  • Please log in to reply
5 replies to this topic

#1 Edmachine

Edmachine

    Young Padawan

  • Members
  • Pip
  • 44 posts
  • Gender:Male
  • Location:Latvia

Posted 02 August 2007 - 02:03 PM

Hello (again :( ), this time I am confused really...

I have to insert players for my online football fantasy league one by one, so I make this query

INSERT INTO players (Name,Age,Nat,St,Tk,Ps,Sh,Ag,KAb,TAb,PAb,SAb,Gam,Sav,Ktk,Kps,Sht,Gls,Ass,DP,Inj,
us) VALUES (Dida,34,bra,16,2,3,2,15,300,300,300,300,0,0,0,0,0,0,0,0,0,0) (but I have it in quotes around them), do it with PHPMyAdmin, but it gives out this error:

#1062 - Duplicate entry '0' for key 1

Since the players are new, everything by default is 0 (except skills, ability points, and everything that is not 0). What does it really mean, and how to solve it?

Also, is there an easier way to add more players at one time (without entering their skills one by one)?

Thanks in advance :).

#2 _*Creative Insanity_*

_*Creative Insanity_*
  • Guests

Posted 02 August 2007 - 03:01 PM

Make sure that you have an ID field and that the ID field auto increments. You are getting that error because there is already a record with ID of 1. So check your database and see if the ID field has the extra option of auto_increment selected.

#3 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 02 August 2007 - 05:20 PM

The problem doesn't have to do with an ID field. He doesn't have an ID field. Its that he has some field set to be a unique key of some kind (unique and index are the only kinds that i believe care).

See if any of your fields are set to be a "key" and remove the key. If you got phpMyAdmin i believe all you have to do is click a little red x (the key information can be found in the left hand box below the table structure).

#4 Edmachine

Edmachine

    Young Padawan

  • Members
  • Pip
  • 44 posts
  • Gender:Male
  • Location:Latvia

Posted 03 August 2007 - 12:24 AM

Actually I have an ID field, but I somehow forgot to set it to auto_increment :rolleyes: . Silly me! :D

Thanks, for pointing that out :). But is there an easier way, to add more users in one time?

Can I do this:

INSERT INTO players (allmycolumns,allmycolumns,almycolumns) VALUES (allplayerinfo,allplayerinfo,allplayerinfo)

?

#5 .CJ

.CJ

    Young Padawan

  • Members
  • Pip
  • 114 posts
  • Gender:Male
  • Location:Leeds, UK

Posted 03 August 2007 - 08:57 AM

Use a while loop.

#6 Edmachine

Edmachine

    Young Padawan

  • Members
  • Pip
  • 44 posts
  • Gender:Male
  • Location:Latvia

Posted 03 August 2007 - 09:21 AM

Umm... how? I am inserting them trough PHPMyAdmin...

Oh, and yeah, I found out that I can't do multiple users in one query ;).




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users