ok... here is my problem... how do i insert a null on the database? this <oprtion value=""></option> doesnt insert a null
You will have to see if the value is equal to "" then substitue that for that code that will produce a NULL within PHP. Sorry I dont have more info as PHP isn't my language.
value="" does not mean that its null. rather it means empty string. you know the difference between empty string and null value yes nor php is my language. but I can tell you to insert null value you have check programettically certain condition and insert NULL then
I don't think it's possible to insert the field as NULL with PHP. You can only insert it as a "string" instead of identified as "unknown data" (NULL). Set that field option within DB as "ALLOW NULL". Any empty value or "" inserted will be treated or updated as NULL.
When you're checking for the value of the drop down, you might want to make the value of your empty option "null". This gives PHP something to check against for how to run the sql query. I'm assuming that what you're wanting to do is start with an initially selected option that gives 'em instructions or ensures that they don't overlook the dropdown by leaving it on the first value. Let's assume that you're doing this for some sort of shopping cart and the dropdown deals with the color of a product. Options might be blue, red, green. So, you'd have a dropdown with name/value pairs of "Select Color"/"null" , "Blue"/"b" , "Red"/"r" , "Green"/"g" So, you'd do the following: if($dropdown == "null") { $sql_insert="INSERT INTO product (product_color) values (null)"; //Note that the value null is not in quotes so it isn't interpreted as a string with the characters n-u-l-l, but is instead a predefined value. } else { $sql_insert="INSERT INTO product (product_color) values ('$dropdown')"; } In theory, this should work. It might be worth a try though, as it's just one if statement that isn't going to drastically change things.
thanks trippallen, thats what i suspected... i have to write an extra query for nulls pretty anoying everything works ok with "" on suposly null fields... but i know that that is not the right way to do it... gota fix my code all over, boring... i will leave this minor bug to later. Anyway... now i already know that i have to use a condition. thx