Jump to content

need help with update

- - - - -

  • Please log in to reply
2 replies to this topic

#1
ckdoublenecks

ckdoublenecks

    Newbie

  • Members
  • Pip
  • 5 posts
This program is to be used at the end of each month to begin
the month with fresh values. When executed there are no
errors, the message "Records have been updated" is displayed,
but no records are changed?

<?php

$stat = mysql_connect("localhost","root","");

$stat = mysql_select_db("prerentdb");

$query = "SELECT name FROM payments Where apt='$apt'";

$stat = @mysql_fetch_assoc(mysql_query($query));

echo $stat["name"];

$result= mysql_query("select * from payments");

while($row=mysql_fetch_array($result))

{

$id=$row['id'];

$paidsum=$row['paidsum'];

$rentdue=$row['rentdue'];

$prevbal=$row['prevbal'];

$latechg=$row['latechg'];

// if no payment or partial payment, add $10 to latechg field

// and amount not paid to prevbal field

if ($paidsum < $rentdue)

{

$latechg = $latechg + 10;

$owe = $rentdue - $paidsum;

$prevbal = $prevbal + $owe;

}

// if over-payment and late field not "L", subtract over-payment

// from prevbal field

if ($paidsum > $rentdue && $late |= 'L')

{

$sub = $paidsum - $rentdue;

$prevbal = $prevbal - $sub;

}

// refresh every record - give every record the below values

$amtpaid = 0;

$hudpay = 0;

$tentpay = 0;

$datepaid = ' ';

$late = ' ';

$paidsum = 0;

$comments = ' ';


$sql = "UPDATE payments SET

$amtpaid, $prevbal, $hudpay, $tentpay, $datepaid, $late, $comments, $paidsum";


mysql_query($sql) ;

}

echo "Records have been updated";

?>


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
You aren't setting your fields to values. The SQL you are sending is "UPDATE payments SET 0, ???, 0, 0, , , , 0" That isn't a valid SQL statement, and certainly won't update your field values. You want something like
$sql = "UPDATE payments SET amtpaid=$amtpaid, prevbal=$prevbal, hudpay=$hudpay, tentpay=$tentpay, datepaid=$datepaid, late=$late, comments=$comments, paidsum=$paidsum";

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200

Quote

$late |= 'L'
| is inclusive OR, I believe you meant ! as in NOT
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users