Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 03-28-2004, 08:45 AM   #1
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.

Last edited by spoody_goon; 03-28-2004 at 08:46 AM.
Old 03-28-2004, 09:41 AM   #2
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')


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

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

Original Poster
Rep: Reputation: 30


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 02:52 PM
PHP insert. agallant Programming 4 08-17-2004 02:36 PM
PHP "for.. loop" to insert into mysql Boby Programming 10 05-29-2004 10:07 AM
I need to insert and post PHP MYSQL DropHit Programming 2 02-18-2004 11:21 PM
Why MySQL Error on INSERT INTO....? pnh73 Programming 2 11-01-2003 05:53 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:06 AM.

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