I'm trying to read the taxrate from the database table and use it with values from another table. the database and table are correct as is the field (taxrate) from the table, value is 0.06. Then I'm trying to multiply that value by the value of a field from another table (charges) then update the table . since it doesn't update, I tried echoing the two values but 0 is displayed for both. Will someone advise me?
<?php
mysql_connect("localhost","root","");
mysql_select_db(numbersdb) or die( "Unable to select database");
$query = "SELECT taxrate FROM numbdata ";
mysql_fetch_assoc(mysql_query($query));
$result=mysql_query($query);
// include("getpercent.php");
$taxrate = $_POST['taxrate'];
echo "taxrate ".$data['taxrate'];
mysql_connect(localhost,root,"");
mysql_select_db(oodb) or die( "Unable to select database");
$query = "SELECT id, tax,charges,datediff(curdate(),duedate) AS dayslate FROM oocust WHERE pd = ' '";
mysql_fetch_assoc(mysql_query($query));
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
$id=$row['id'];
$amtdue = $row['amtdue'];
$shipamt = $row['shipamt'];
$charges = $row['charges'];
$tax = $charges * $taxrate;
$amtdue = $charges + $tax + $shipamt;
echo "tax is $tax <br /><br />";
$days_late = ($row['dayslate'] > 0)?$row['dayslate'] : 0;
$sql = "UPDATE oocust SET tax = " . $tax . ", amtdue = " . $amtdue . ", dayslate = " . $days_late . " WHERE
id='$id'";
mysql_query($sql) ;
$err=mysql_error();
if($err!="")
{
echo "Error in $sql: $err\n";
}
}
echo "Invoice Prep completed";
?>