0

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";
?>
4
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by ko ko
0

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.

Edited by minitauros: n/a

0

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

0

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 = ' '";
0
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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.