Jump to content

Problem with updating a mysql field to 0


Shadowing

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.