php - INSERT NULL Values not working instead i get 0.000 -


I am trying to input a form into a database that uses numeric values ​​(mainly decimal) < / P>

This form updates and inserts, but I want to NULL to enter the field in the database.

If I leave a field blank, in code> 0.000 database I have a set database on NULL = YES

Can I use it for all 14 text boxes to do this?

This is my code:

  & lt ;? Php if (isset ($ _ POST ['submit']) {$ date2 = date ("ymd"); // date of date of tank $ time 2 = date ("h: i: s", time () - 3600); // extra time for the tank extra $ test1 = $ _POST ['test1']; $ Test2 = $ _POST ['test2']; $ Test3 = $ _POST ['test3']; $ Test4 = $ _POST [' Test4 ']; $ test5 = $ _POST [' test5 ']; $ Test6 = $ _POST [' test6 ']; $ Test7 = $ _POST [' test7 ']; $ Test8 = $ _POST [' test8 ']; $ Test9 $ $ _POST ['test9']; $ test10 = $ _POST ['test10']; $ Test11 = $ _POST ['test11']; $ Test12 = $ _POST ['test12']; $ Test13 = $ _POST [' Test13 ']; $ test14 = $ _POST [' test14 ']; $ time = $ _POST [' time ']; $ date = $ _POST [' date ']; $ month = $ _POST [' month ']; $ day = $ _POST ['day']; $ Active1 = $ _POST ['active 1']; $ active 2 = $ _POST ['active 2']; $ s $ 3 = $ _POST ['Active 3']; $ Active 4 = $ _POST ['active4']; $ Active 5 = $ _POST ['Active 5']; $ Active 6 = $ _POST ['Active 6']; $ Active 7 = $ _POST ['active7']; $ active 8 = $ _POST ['active8']; $ active 9 = $ _POST ['active9']; $ active10 = $ _POST ['active 10']; $ Active 11 = $ _POST ['active 11']; $ Active $ 12 = $ _POST ['active 12']; $ Active 13 = $ _POST ['active 13']; $ Active 14 = $ _POST ['active 14']; $ Tank = $ _POST ['tank']; $ Insert = "Include the test SET member_id = '$ _ session [SESS_MEMBER_ID]', test1 = '$ test1', test2 = '$ test2', test3 = '$ test3', test4 = '$ test4', test5 = '$ Test5' test6 = '$ test6', test7 = '$ test7', test8 = '$ test8', test9 = '$ test9', test10 = '$ test10', test11 = '$ test11', test12 = '$ Test12 ', test13 =' $ test13 ', test14 =' $ test14 ', date =' $ date ', month =' $ month ', day =' $ day ', time =' $ time ', active1 =' $ active1 'Active2 =' $ active2 ', active3 =' $ active3 ', activ4 =' $ active4 ', active5 =' $ active5 ', activ6 =' $ active6 ', active7 =' $ active7 ', active8 =' $ active8 ' Active 9 = '$ active 9', active 10 = '$ active 10', active 11 = '$ active 11', active 12 = '$ active 12', active 13 = '$ active 13', active 14 = '$ Active 14 ', tank_id =' $ tank '";  

When a field is empty or someone clears it on editing (I suppose Is that even possible), the value is an empty string.

To do this, make sure that you enter NULL in empty strings, then you can do this (for all the variables which NULL ):

  $ test1 = ($ _POST ['test1'] === '')? Zero: $ _POST ['test1'];  

This will actually set the value to NULL instead of an empty string, which will be inserted on 0 if inserted.

And you should use ready-made statements for your SQL inserts.

Edit: Also keep in mind that when you try to insert your NULL value, you will see the NULL No more 'NULL' .

Edit 2: A temporary solution that works here will remove the quote from the SQL statement. And add them to the assignment:

  $ test1 = ($ _POST ['test1'] === '')? Note: ("'". (Float) $ _POST [' test1 ']. "' '); ...  

and:

  $ Insert = "Include in test SET member_id = '$ _ session [SESS_MEMBER_ID]', test1 = $ test, test2 = $ test2, test3 = $ test3, ...  

I less To get rid of SQL injection problem less than (float) is used ( mysql_real_escape_string () may be better, do not know, do not use it any more ...), but with the real solution it is more of a hack. Please switch with a statement ready bound variable .


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -