Page 1 of 1

need help with update

Posted: Wed Apr 20, 2011 4:24 pm
by ckdoublenecks
the below code is intended to update the database with the calculated taxes and days late. It just displays the values in the records but no update. the taxes displayed were already there. Can someone please help?
Charges: 160.00 Due Date: 02/07/2011 Days Late: N/A Tax: 0.00

Charges: 88.00 Due Date: 4/15/2011 Days Late: N/A Tax: 0.00

Charges: 10.00 Due Date: 1/25/2011 Days Late: N/A Tax: 0.60

Charges: 300.00 Due Date: 4/15/2011 Days Late: N/A Tax: 18.00

Charges: 60.00 Due Date: 2/21/2011 Days Late: N/A Tax: 0.00

Charges: 50.00 Due Date: 5/5/2010 Days Late: N/A Tax: 3.00

Charges: 31.80 Due Date: 4/13/2011 Days Late: N/A Tax: 1.91

Code: Select all

<?php
$stat = mysql_connect(localhost,root,"");
$stat = mysql_select_db(oodb) or die( "Unable to select database");
$query = "SELECT id, tax,charges,datediff(curdate(),duedate) AS dayslate FROM oocust WHERE pd = ' '"; 
$stat = @mysql_fetch_assoc(mysql_query($query));
$result= mysql_query("select * from oocust");
while($row=mysql_fetch_array($result))
   {
$id=$row['id']; 
$tax = $row['tax'];
$charges = $row['charges'];
$tax = $charges * .06;
$days_late = ($row['dayslate'] > 0)?$row['dayslate'] . " days":'N/A';  
echo "<p> Charges: " . $row['charges'] . " Due Date: " . $row['duedate'] .   " 
Days Late: $days_late Tax: " . $row['tax'] . "</p>"; 
   }
$sql = "UPDATE oocust SET
tax = '$tax', dayslate = '$days_late'
WHERE id='$id'";
 mysql_query($sql) ;
$err=mysql_error();
if($err!=""){
  echo "Error in $sql: $err\n";
echo "Invoice Prep completed";
}
 ?>

Re: need help with update

Posted: Wed Apr 20, 2011 4:54 pm
by McInfo
Describe oocust.