need help with update

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ckdoublenecks
Forum Newbie
Posts: 21
Joined: Mon Jan 24, 2011 6:47 pm

need help with update

Post 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";
}
 ?>
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: need help with update

Post by McInfo »

Describe oocust.
Post Reply