LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 06-24-2004, 03:42 PM   #1
agallant
Member
 
Registered: Oct 2003
Location: D.C USA
Distribution: Redhat 9. Thinking about Slackware
Posts: 166

Rep: Reputation: 30
MySQL Primairy Key problem


Ok, I may be doing some thing wrong here. I have 2 tables and one form that inserts to the tables. When i fill in the form the first record gets inserted in to boath tables. but when i try to insert a 2nd record i get a "Duplicate entry '0' for key 1." error

I am using a php page that i developed in Dreamweaver MX. Both of the keys are named the same and are an decimal.

ANy ideas?
 
Old 06-24-2004, 04:17 PM   #2
logicdisaster
Member
 
Registered: Jun 2004
Posts: 41

Rep: Reputation: 15
could we see some code?
could be bad sql or bad php
 
Old 06-24-2004, 04:40 PM   #3
agallant
Member
 
Registered: Oct 2003
Location: D.C USA
Distribution: Redhat 9. Thinking about Slackware
Posts: 166

Original Poster
Rep: Reputation: 30
Wen i submit through the web page i get this error:
uplicate entry '0' for key 1

now i noticed using CocaMySQL that the pkey default value for the PKey is 0. If i change it to 1 or i can insert a nother row, then i get the same error message. If i chance it to 2 it will work again but then stops when a nother row is added. I can not change this default field. if i try i dont get an error but it defailst back to 0
MySQL 16:38:03] SHOW INDEX FROM `Venders`
[MySQL 16:38:15] ALTER TABLE `Venders` CHANGE `id` `id` decimal(10,0) UNSIGNED NOT NULL DEFAULT ""
[MySQL 16:38:15] SHOW COLUMNS FROM `Venders`
[MySQL 16:38:15] SHOW INDEX FROM `Venders`

If i change it to Null i get:
[MySQL 16:39:39] ALTER TABLE `Venders` CHANGE `id` `id` decimal(10,0) NOT NULL DEFAULT NULL
[ERROR 16:39:39] Invalid default value for 'id'

Is there some Syntax that i am missing? i am fairly new to SQL in general.
 
Old 06-24-2004, 05:26 PM   #4
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,617

Rep: Reputation: 136Reputation: 136
Try :
Code:
ALTER TABLE `Venders` CHANGE `id` `id` decimal(10,0) NOT NULL auto_increment;
 
Old 06-25-2004, 09:43 AM   #5
agallant
Member
 
Registered: Oct 2003
Location: D.C USA
Distribution: Redhat 9. Thinking about Slackware
Posts: 166

Original Poster
Rep: Reputation: 30
Didn't work. any other ideas?
 
Old 06-25-2004, 09:55 AM   #6
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,617

Rep: Reputation: 136Reputation: 136
Can you post your code to insert a new row please ?
 
Old 06-28-2004, 12:12 AM   #7
sonesay
Member
 
Registered: May 2004
Location: AUCKLAND
Distribution: Fedora core 2 , RH9
Posts: 64

Rep: Reputation: 15
its probably how your tables are set up...
describe table;
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bugzilla - MySQL - perl - DBD::mysql install problem Runningonair Linux - Software 8 10-12-2007 01:42 AM
Bad Key / No Key Error MySql wasabi Linux - Software 1 04-19-2005 07:06 PM
Primairy Key agallant Programming 6 06-28-2004 04:43 PM
Mysql Foreign Key munna_502 Linux - Software 0 06-12-2004 05:31 PM
MySQL server problem after linking (mysql.sock) ewijaya Linux - General 4 01-19-2004 10:46 AM


All times are GMT -5. The time now is 05:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration