LinuxQuestions.org
Register a domain and help support LQ
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 03-28-2004, 09:45 AM   #1
spoody_goon
Member
 
Registered: Sep 2003
Location: Michigan USA
Distribution: Mandrake, DamnSmallLinux, VectorLinux
Posts: 416

Rep: Reputation: 30
php mysql insert null value


I have a problem with my php/mysql program. First the tables.

Dealer(dealer_id, first_name, last_name, phone, email, direct_offer)
Booths(booths, dealer_id)

The problem when I add to the Booths table without a dealer_id the value of 0 is inserted into the database instead of NULL. There is no cascading between Dealer.dealer_id and Booths.dealer_id. Booths.dealer_id isn't a not null field and its default value is NULL.

Here is the insert code:

$input_sql="INSERT INTO booths (booths, dealer_id) VALUES ('$booths', '$dealer_id')";
mysql_query("$input_sql")or die("(".mysql_errno().") Error:".mysql_error());


If you require more information please ask.
Thanks

Last edited by spoody_goon; 03-28-2004 at 09:46 AM.
 
Old 03-28-2004, 10:41 AM   #2
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
If you are specifically stating a dealer_id to insert, it will never use the default. You have one of 2 choices, but both require checking if dealer_id should be NULL ahead of time. If so, you can execute one of the following:

INSERT INTO Booths(booths) VALUES('$booths')

OR

INSERT INTO Booths(booths, dealer_id) VALUES ('$booths', null)

Note: There are no single parenthesis around the null keyword...
 
Old 03-28-2004, 11:20 AM   #3
spoody_goon
Member
 
Registered: Sep 2003
Location: Michigan USA
Distribution: Mandrake, DamnSmallLinux, VectorLinux
Posts: 416

Original Poster
Rep: Reputation: 30
Thanks
 
  


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
Insert problem Php petenyce Linux - Newbie 1 10-12-2005 03:52 PM
PHP insert. agallant Programming 4 08-17-2004 03:36 PM
PHP "for.. loop" to insert into mysql Boby Programming 10 05-29-2004 11:07 AM
I need to insert and post PHP MYSQL DropHit Programming 2 02-19-2004 12:21 AM
Why MySQL Error on INSERT INTO....? pnh73 Programming 2 11-01-2003 06:53 PM


All times are GMT -5. The time now is 08:35 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