1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

need help with update

Discussion in 'Web Design & Development' started by ckdoublenecks, Jan 24, 2011.

Thread Status:
Not open for further replies.
Advertisement
  1. ckdoublenecks

    ckdoublenecks Thread Starter

    Joined:
    May 28, 2009
    Messages:
    112
    this code clears the fields. if statements aren't being executed?
    PHP:
    <?php
    include ('getnames.php');
    if(
    $paidsum $rentdue
    {
    $latechg == $latechg 10;
    }
    if(
    $paidsum == $rentdue || $late == 'L')
    {
    $amtpaid == 0
    $prevbal == 0
    $latechg == 0
    $hudpay == 0;
    $tentpay == 0
    $datepaid == ' '
    $late == ' '
    $comments == ' '
    $paidsum == 0;
    }
    $sql "UPDATE payments SET
     amtpaid = '" 
    mysql_real_escape_string($_POST['amtpaid']) . "',
     prevbal = '" 
    mysql_real_escape_string($_POST['prevbal']) . "',
     latechg = '" 
    mysql_real_escape_string($_POST['latechg']) . "',
     hudpay = '" 
    mysql_real_escape_string($_POST['hudpay']) . "',
     tentpay = '" 
    mysql_real_escape_string($_POST['tentpay']) . "',
     datepaid = '" 
    mysql_real_escape_string($_POST['datepaid']) . "',
     late = '" 
    mysql_real_escape_string($_POST['late']) . "',
     comments = '" 
    mysql_real_escape_string($_POST['comments']) . "',
     paidsum = '" 
    mysql_real_escape_string($_POST['paidsum']) . "'";
    mysql_query($sql) or die("Update query failed.");
    echo 
    "Records have been updated";
    ?>
     
     
     
  2. ehymel

    ehymel

    Joined:
    Aug 12, 2007
    Messages:
    696
    Probably the conditions aren't being satisfied, so the code inside the if blocks don't get run.

    To check this, try to echo the variables to the screen so you can see the values:

    PHP:
    <?php
    include ('getnames.php');
    echo 
    "paidsum is $paidsum , while rentdue is $rentdue <br>";
    if(
    $paidsum $rentdue
    ...
     
  3. ckdoublenecks

    ckdoublenecks Thread Starter

    Joined:
    May 28, 2009
    Messages:
    112
    it shows no values there but this is a controlled test. I keep going back and putting the values back each time I run this. I copied the database table ?
    id name apt amtpaid rentdue prevbal hudpay tentpay datepaid late latechg comments paidsum 1name1k10500000 2name2k23005000030001/19/2011 3003name3k35505500055001/05/2011 550 4name4k45105000051001/09/2011L510 5name5K55755500057501/03/2011 575
     
  4. ehymel

    ehymel

    Joined:
    Aug 12, 2007
    Messages:
    696
    Doesn't really matter what the database shows... if the php script doesn't show the values then the if block will not run.

    You could try hard-coding the values (just for testing purposes of course):

    PHP:
    <?php
    include ('getnames.php');
    $paidsum 2300;
    $rentdue 5000;
    echo 
    "paidsum is $paidsum , while rentdue is $rentdue <br>";
    if(
    $paidsum $rentdue
    ...
    Also, I don't know how you're storing & retrieving the values from the database, but make sure you're handling these numbers specifically as numbers (as opposed to strings) with intval() or floatval() as appropriate.
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/976787

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice