Jump to content

simple math


tobimichigan

Recommended Posts

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");
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

$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?!?

Link to comment
Share on other sites

$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?
Link to comment
Share on other sites

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']);

Link to comment
Share on other sites

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']);

Link to comment
Share on other sites

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)

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.