SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    need help with update

    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 Code:
    <?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"];
    $resultmysql_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. #2
    SitePoint Zealot Amit Yaron's Avatar
    Join Date
    Jan 2011
    Location
    Hod Haharon, Israel
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As far as I know, this is not the syntax of an Update statement.
    It should be something like:
    Code:
    $sql=<<<EOQ
    UPDATE payment
    SET
      amtpaid=$amtpaid,
      prevbal=$prevbal,
      hudpay=$hudpay,
      rentpay=$rentpay,
      datepay='$datepay'
    WHERE ....
    EOQ;
    Check the returned value from mysql_query before echoing that records have been updated.
    If the returned value is FALSE, type mysql_error().

  3. #3
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    UPDATE payments SET $amtpaid, $prevbal, $hudpay, $tentpay, $datepaid, $late, $comments, $paidsum
    Isn't a valid query.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •