View Single Post
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
  #4
Nov 18th, 2008
Keith,

You can insert records in a table exactly as cali_dotcom does, it is not oblgatory to do it by mentioning the column names where you want to insert data. Your approach is OK when you want to insert data in different order than the columns in the table.
The problem with the script is that "NULL" is different from NULL without quotes. MySQL considers "NULL" to be a string and does not validate it as the value NULL.

So this should work perfectly
  1. $sql = 'INSERT INTO article_fields VALUES(NULL,"'.$new_text.'","'.$field_type.'")';

Also, when inserting numbers it is good to insert them not surrounded by "" as MySQL validates numbers correctly.
" Of all the things I've lost,
I miss my mind the most...."
Mark Twain
Reply With Quote