ckdoublenecks Posted April 27, 2011 Share Posted April 27, 2011 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"; ?> Quote Link to comment Share on other sites More sharing options...
mr.php47 Posted May 2, 2011 Share Posted May 2, 2011 is this part correct ? $query = "SELECT id, tax,charges,datediff(curdate(),duedate) AS dayslate FROM oocust WHERE pd = ' '"; 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.