mac007 Posted June 6, 2009 Share Posted June 6, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/161214-why-i-need-to-enter-00-in-order-for-number-entry-to-be-updated-and-not-just-0/ Share on other sites More sharing options...
Maq Posted June 6, 2009 Share Posted June 6, 2009 I'm confused, what does "it doesn't take it" refer to? Quote Link to comment https://forums.phpfreaks.com/topic/161214-why-i-need-to-enter-00-in-order-for-number-entry-to-be-updated-and-not-just-0/#findComment-850681 Share on other sites More sharing options...
mac007 Posted June 6, 2009 Author Share Posted June 6, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/161214-why-i-need-to-enter-00-in-order-for-number-entry-to-be-updated-and-not-just-0/#findComment-850684 Share on other sites More sharing options...
PFMaBiSmAd Posted June 6, 2009 Share Posted June 6, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/161214-why-i-need-to-enter-00-in-order-for-number-entry-to-be-updated-and-not-just-0/#findComment-850688 Share on other sites More sharing options...
mac007 Posted June 6, 2009 Author Share Posted June 6, 2009 hmmm.. let me check that over.. maybe you are right, maybe there is an "echo" problem... Quote Link to comment https://forums.phpfreaks.com/topic/161214-why-i-need-to-enter-00-in-order-for-number-entry-to-be-updated-and-not-just-0/#findComment-850692 Share on other sites More sharing options...
mac007 Posted June 7, 2009 Author Share Posted June 7, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/161214-why-i-need-to-enter-00-in-order-for-number-entry-to-be-updated-and-not-just-0/#findComment-851062 Share on other sites More sharing options...
Ken2k7 Posted June 7, 2009 Share Posted June 7, 2009 If $Sep is null, $Sep == 0 is true by PHP semantics. Either put the elseif case before the if $Sep == 0 or change your == to ===. Quote Link to comment https://forums.phpfreaks.com/topic/161214-why-i-need-to-enter-00-in-order-for-number-entry-to-be-updated-and-not-just-0/#findComment-851065 Share on other sites More sharing options...
mac007 Posted June 7, 2009 Author Share Posted June 7, 2009 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()... Quote Link to comment https://forums.phpfreaks.com/topic/161214-why-i-need-to-enter-00-in-order-for-number-entry-to-be-updated-and-not-just-0/#findComment-851075 Share on other sites More sharing options...
Ken2k7 Posted June 7, 2009 Share Posted June 7, 2009 Wait, you're doing that in MySQL? Quote Link to comment https://forums.phpfreaks.com/topic/161214-why-i-need-to-enter-00-in-order-for-number-entry-to-be-updated-and-not-just-0/#findComment-851079 Share on other sites More sharing options...
mac007 Posted June 8, 2009 Author Share Posted June 8, 2009 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'"); Quote Link to comment https://forums.phpfreaks.com/topic/161214-why-i-need-to-enter-00-in-order-for-number-entry-to-be-updated-and-not-just-0/#findComment-851310 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.