Jump to content

Why I need to enter 0.0 in order for number entry to be updated; and not just 0


mac007

Recommended Posts

Hi all:

 

I have this slight problem, where I always have to enter "0.0" in order for my record to be updated properly; otherewise if I just put "0" it doesnt take it and remains null... ???  I'd like to simply enter 0 and have it update... am I missing a function?  my table-field is setup as float(11,2). Here's the basic sql statement I'm using (each month refers an amont to be updated). Is it beacuse I am NOT filtering the data as integers? or numbers?? 

 

$updateQuery = mysql_query("UPDATE BUDGETS SET Jan=$Jan, Feb=$Feb, Mar=$Mar, Apr=$Apr, May=$May, Jun=$Jun, Jul=$Jul, Aug=$Aug, Sep=$Sep, Oct=$Oct, Nov=$Nov, BUDGETS.Dec=$Dec, notes='$notes' WHERE recordid = $accountid AND recordcustid = '$member'");

 

Thanks in advance...

Link to comment
Share on other sites

Hi, Maq...

 

I mean that if I just enter "0", the record doenst update and simply remains "null". But if I type "0.0", then it does update and shows updated record as 0.0. I want to simply type "0", and then for it to update and show 0.0 also...

Link to comment
Share on other sites

There must be something wrong in your code that is displaying the information. I just created a table with a column float(11,2) and was able to update a null value to 0.00 by using a 0 in an UPDATE query.

 

Have you directly examined the values in the database using a tool like Mysql Query Browser? Are you sure of your table definition? Are you sure your UPDATE query got executed and the value actually got changed or is it still a null and your code is displaying nulls as 0?

Link to comment
Share on other sites

Hi PFM... thanks for your help,  I got this to work, kind off with this code:

 

$Sep= $_POST['Sep']; if ($Sep == 0) { $Sep = "0.0";}

 

BUT NOW, if the form fields are left blank, then it automatically inserts 0.00 (not blank, which I also want the DB fields to remain).

I tried to modify to this, but didnt seem to work...

 

$Sep= $_POST['Sep']; if ($Sep == 0) { $Sep = "0.0";} elseif(is_null($Sep)) { $Sep = 'NULL';}

 

Any ideas?

Thanks again...

Link to comment
Share on other sites

Thanks, Ken...

 

I tried your code but still doing same thing... I reversed if / elseif statements, and added === as you suggested; but still no luck...

 

$Sep= $_POST['Sep']; if(is_null($Sep)) { $Sep = 'NULL';} elseif ($Sep === 0) { $Sep = "0.0";}

 

I dotn get why mysql is not understanding the is_null() function... I mean that pretty much indicates that field is blank, doenst it?  as opposed to empty()...

Link to comment
Share on other sites

sorry, didnt answer earlier... had to step out for a while..

 

yes, it's a mysql database; but the validation is in php first. Then the value gets UPDATED in this mysql statement:

 

$updateQuery = mysql_query("UPDATE BUDGETS SET Jan=$Jan, Feb=$Feb, Mar=$Mar, Apr=$Apr, May=$May, Jun=$Jun, Jul=$Jul, Aug=$Aug, Sep=$Sep, Oct=$Oct, Nov=$Nov, BUDGETS.Dec=$Dec, notes='$notes' WHERE recordid = $accountid AND recordcustid = '$member'");

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.