Duplicate entry '' for key 2

Reply

Join Date: Oct 2006
Posts: 232
Reputation: Rhyan is an unknown quantity at this point 
Solved Threads: 24
Rhyan's Avatar
Rhyan Rhyan is offline Offline
Posting Whiz in Training

Re: Duplicate entry '' for key 2

 
0
  #11
Nov 18th, 2008
OK, what I mean is the following

$new_text is the variable name by which you refer to it in your code. The variable value is the value of $_GET['whatever'].

My question is - your string
  1. INSERT INTO `article_fields`(`field_title`, `field_type`) VALUES("'.$new_text.'","'.$field_type.'")
looks exactly as you would have it typed into your code.
But when you call the page wich contains ECHO "INSERT STRING HERE $variable"; and PHP parses the code - the html output should be something like
INSERT STRING HERE my value.

So what bothers me in your post is that if the HTML output of the echo command is exactly as you have it posted here, there is something wrong in the formatting of your php string.

Do you understand me better now?
" Of all the things I've lost,
I miss my mind the most...."
Mark Twain
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,225
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 166
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Duplicate entry '' for key 2

 
0
  #12
Nov 18th, 2008
the ` (which are different than ') are not necessary, but I see phpMyAdmin and other programs use them a lot so it kind of became a habit of mine. it also helps me identify database and table names in the queries i write. i wrote the column names in so we could avoid silly errors that i figured s/he would have.

cali_dotcom:

if you have some code to look at, post it. maybe we can find if something else is preventing this from working, because i know the sql i posted works.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1
Reputation: correio24 is an unknown quantity at this point 
Solved Threads: 0
correio24 correio24 is offline Offline
Newbie Poster

Re: Duplicate entry '' for key 2

 
0
  #13
Jan 12th, 2009
It seems your table is not auto-incrementing...
Try to add "AUTO_INCREMENT" to your primary key:

CREATE TABLE table (

id_primary INT UNSIGNED NOT NULL AUTO_INCREMENT...
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,267
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 159
almostbob's Avatar
almostbob almostbob is online now Online
Nearly a Posting Virtuoso

Re: Duplicate entry '' for key 2

 
0
  #14
Jan 14th, 2009
mysql_query(sprintf("insert into article_fields
(new_text, fields_type) values
('%s', '%s');",
$new_text, $field_type))
Failure is not an option It's included free
If at first you dont succeed, join the club
Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC