tobimichigan Posted March 25, 2010 Share Posted March 25, 2010 Code Gurus Please help. I am trying to make a calculation from 2 boxes namely $apaid & $adue to make a third $adebt like saying $adebt=$adue-$apaid All three values would then go right into the db. But whenever I click the submit form the form the $adebt column remains blank while other values go straight in. Please can someone tell me what I'm doing wrong here? <?php //session_start(); include("cn.php"); $adue=$_GET['adue']; $apaid=$_GET['apaid']; //$adebt=$adue-$apaid; //$username=$_GET['[$_SESSION[username]']; $adno= mysql_real_escape_string($_POST['adno']); $adue= mysql_real_escape_string($_POST['adue']); $apaid = mysql_real_escape_string($_POST['apaid']); $adebt=($adue-$apaid)== mysql_real_escape_string($_POST['adebt']); $datereg = mysql_real_escape_string($_POST['datereg']); $username= mysql_real_escape_string($_POST['username']); $sql= "Insert into receipts(adno,adue,apaid,adebt,datereg,username) values('$adno','$adue','$apaid','$adebt',SYSDATE(),'$_SESSION[username]')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()." SQL: ".$sql); } else header ("Location:Receipt_Success.php"); ?> Quote Link to comment Share on other sites More sharing options...
Mchl Posted March 25, 2010 Share Posted March 25, 2010 Just like you did it in your other topic: $adebt=$adue-$apaid; are you having any problems with that? [edit] And this: $adebt=($adue-$apaid)== mysql_real_escape_string($_POST['adebt']); has no chance of doing anything useful. Quote Link to comment Share on other sites More sharing options...
ignace Posted March 25, 2010 Share Posted March 25, 2010 $adebt=($adue-$apaid)== mysql_real_escape_string($_POST['adebt']); After this $adebt==false; as $_POST['adebt'] != $adue-$apaid So it's $adebt = mysql_real_escape_string($_POST['adebt']); $adebt = $adue - $apaid; As you saw nothing that tells me you used varchar or something for your integer fields otherwise you would have got 0 However this makes no sense at all?!? Quote Link to comment Share on other sites More sharing options...
tobimichigan Posted March 25, 2010 Author Share Posted March 25, 2010 $adebt=($adue-$apaid)== mysql_real_escape_string($_POST['adebt']); After this $adebt==false; as $_POST['adebt'] != $adue-$apaid So it's $adebt = mysql_real_escape_string($_POST['adebt']); $adebt = $adue - $apaid; e However this makes no sense at all?!? I don't understand what you mean ignance. Mchl, the accurate value to be returned by the calculation is indicating 0 instead of the math value still what am I doing wrong? Quote Link to comment Share on other sites More sharing options...
Mchl Posted March 25, 2010 Share Posted March 25, 2010 Mchl, the accurate value to be returned by the calculation is indicating 0 instead of the math value still what am I doing wrong? THIS. This is wrong! $adebt=($adue-$apaid)== mysql_real_escape_string($_POST['adebt']); Quote Link to comment Share on other sites More sharing options...
ignace Posted March 25, 2010 Share Posted March 25, 2010 Mchl, the accurate value to be returned by the calculation is indicating 0 instead of the math value still what am I doing wrong? THIS. This is wrong! $adebt=($adue-$apaid)== mysql_real_escape_string($_POST['adebt']); Which also explains the 0 as false in an integer context shows up as 0 and like Mchl said it's: $adebt=($adue-$apaid); It's that simple get rid of that .._string($_POST['adebt']); Quote Link to comment Share on other sites More sharing options...
ignace Posted March 25, 2010 Share Posted March 25, 2010 I also want to give you some friendly advice: buy a book on software development and read the sections about variable types and conversions very carefully. A good start: http://www.php.net/manual/en/language.types.php You should just like me be able to tell that after the instruction: $adebt=($adue-$apaid)== mysql_real_escape_string($_POST['adebt']); $adebt = false; and that in an integer context it translates to 0 unless $adue - $apaid indeed match adebt in which $adebt = true and 1 shows up in your db if you had used === then $adebt would have always been false (yes, you must be able to tell that in a blink of an eye) Quote Link to comment Share on other sites More sharing options...
tobimichigan Posted March 25, 2010 Author Share Posted March 25, 2010 wait a minute ignace, you said something that seems to strike a cord, I am using a varchar..instead of integer in the column adebt could that be the problem? You sound confusing atimes ignace almost hiting the nail on the head.... could you please be more precise? Quote Link to comment Share on other sites More sharing options...
Mchl Posted March 25, 2010 Share Posted March 25, 2010 I'll try be as precise as I can. Instead of: $adebt=($adue-$apaid)== mysql_real_escape_string($_POST['adebt']); do: $adebt=$adue-$apaid; Quote Link to comment 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.