Jump to content

need help with update


ckdoublenecks

Recommended 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";
?>

Link to comment
Share on other sites

It's always a good idea to echo out your SQL statement ($sql) to see what values you're actually passing in.  My guess is your query is failing, temporarily change this line to:

mysql_query($sql) or die(mysql_error());

Link to comment
Share on other sites

It appears you're missing a bunch of the query...

 

$sql = "UPDATE payments SET $amtpaid, $prevbal, $hudpay, $tentpay, $datepaid, $late, $comments, $paidsum";

 

Should be something like

 

$sql = "UPDATE payments SET `amtpaid` = $smtpaid.."

 

And so on... you actually have to tell it what field you want to update with what new data. Also, string items need to quoted when passed through a query.

Link to comment
Share on other sites

Right now, it appears you're echoing you're success message no matter what, wrap it in a condition would help with error handling. That only notifies if a problem exists, it doesn't fix the issue you have with an unsuccesssful update, which I think MatthewJ is correct about.

 

Add what Maq posted while testing, it's invaluable

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.