Shadowing Posted January 8, 2012 Share Posted January 8, 2012 for some reason i cant update a field to 0. I can change it to any other number but 0 im using INT for the column and trying to update it from a form. I read its a default protection built in. but for this case i need to beable to do this I was reading about all this in mysql manual and they talk about using unassigned to use the range of 0 but idk if I was understanding that correctly. I tried unassigned and other things. Anyone have an idea what i need to do to update a field to 0. using a form input Quote Link to comment https://forums.phpfreaks.com/topic/254601-problem-with-updating-a-mysql-field-to-0/ Share on other sites More sharing options...
The Little Guy Posted January 9, 2012 Share Posted January 9, 2012 some related code of what your doing would be helpful. Quote Link to comment https://forums.phpfreaks.com/topic/254601-problem-with-updating-a-mysql-field-to-0/#findComment-1305653 Share on other sites More sharing options...
Pikachu2000 Posted January 9, 2012 Share Posted January 9, 2012 I'd be interested to know just where in the MySQL manual it says an integer field can't be set to 0. Quote Link to comment https://forums.phpfreaks.com/topic/254601-problem-with-updating-a-mysql-field-to-0/#findComment-1305654 Share on other sites More sharing options...
PFMaBiSmAd Posted January 9, 2012 Share Posted January 9, 2012 It's more likely your php code is doing something like testing if the variable holding the value is empty (which zero is considered to be) or is testing if the variable is true/false (zero is considered to be a false value for loose php comparisons.) What have you done to narrow down the problem and determine exactly what your code and data are doing? Have you echoed out your query statement right after the point where it is being formed so that you both know that the code is being executed at all and that the query statement has the values in it that you expect? Are you sure you are executing the query and that the query executed without any errors? What does your error checking logic in your code tell you? It could be that you have a key defined for the column and you are trying to update it to a value that already exists. Quote Link to comment https://forums.phpfreaks.com/topic/254601-problem-with-updating-a-mysql-field-to-0/#findComment-1305659 Share on other sites More sharing options...
Shadowing Posted January 9, 2012 Author Share Posted January 9, 2012 ahhh yah thats whats going on im testing if the field is not empty first. I changed it from !empty to isset thanks alot PFMaBiSmAd. Yah i need to stop assuming what a problem is and check everything first on the script. I was so certain it was some problem with how i was setting up the column in my sql even though it wasnt. Which is why I didnt post any code. and thanks to Pikachu2000 showing me how to debug a few things. ive been using it alot. I found a better section in the manual that explains this clear for me. This chart clearly says i can use 0 lol. http://dev.mysql.com/doc/refman/5.0/en/integer-types.html there was another section talking about ranges from like example (-2147483648 up to 0 to 2147483647) so i was thinking since it said up to 0 it didnt include 0 lol but apparently not. Quote Link to comment https://forums.phpfreaks.com/topic/254601-problem-with-updating-a-mysql-field-to-0/#findComment-1305705 Share on other sites More sharing options...
Shadowing Posted January 9, 2012 Author Share Posted January 9, 2012 Oh great lol i came up with another issue. I guess isset doesnt care if the form is blank or not so i need to figure out a way to check thats its not empty and 0 is allowed. Was looking at my options in the manual. i tried isset !is_null $var != ' ' But I got this to work "is_numeric" so im guessing this should work fine. Its a INT mysql column and it only accepts numbers from the form also I just realize another flaw in using !empty in the right situation if I typed in something that wasnt a number it would accept and turn the field in mysql to 0. which also interesting would of gave me a way to turn the field to 0 using !empty lol. since 0 means empty if i typed asdf it would of turned it to empty. Using is_numeric is ofcourse better Quote Link to comment https://forums.phpfreaks.com/topic/254601-problem-with-updating-a-mysql-field-to-0/#findComment-1305720 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.