trying to update

Discussion in 'PHP' started by ckdoublenecks, Feb 23, 2011.

  1. #1
    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";
    ?>
    PHP:
     
    ckdoublenecks, Feb 23, 2011 IP
  2. mallorcahp

    mallorcahp Peon

    Messages:
    141
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try turning on error reporting and outputting the result of the query :

     
    mallorcahp, Feb 23, 2011 IP
  3. Simple Link Media

    Simple Link Media Peon

    Messages:
    38
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    A hint: which fields are you trying to update ?

    UPDATE payments SET field1=$value1, field2=$value2, ..
    Code (markup):
    Update your code and it will most likely finally go through.
     
    Simple Link Media, Feb 23, 2011 IP
  4. ckdoublenecks

    ckdoublenecks Guest

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanks for the advice, it's now working except for one thing - is the below expression not valid?
    if ($paidsum > $rentdue && $late != 'L')

    && $late != 'L' is being ignored
     
    ckdoublenecks, Feb 24, 2011 IP
  5. Simple Link Media

    Simple Link Media Peon

    Messages:
    38
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Looks ok to me. What are the values you are working with ?
     
    Simple Link Media, Feb 24, 2011 IP