the below code is intended to update a database file with the no of days late and tax calcs for each record. I'll understand this before I qive up. the subject is the error message.

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

Recommended Answers

All 4 Replies

Lines 28 - 30:

if($err!=""){
echo "Error in $sql: $err\n";
echo "Invoice Prep completed";

You place an opening bracket there, but you never close it.

now I get this:

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\invoice\invcalc.php on line 5
could not execute query at line 4

You have double where in your sql.So replace this

$query = "SELECT invnum FROM oocust [B]Where WHERE[/B] payrec = 'R' AND pd = ' '";

with

$query = "SELECT invnum FROM oocust Where payrec = 'R' AND pd = ' '";
mysql_query("select * from oocust") or die("Faile to select table " . mysql_error());

Using the error handling should be use with the coplex code block. Learn more about Mysql error types here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.