need help with update

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ckdoublenecks
Forum Newbie
Posts: 21
Joined: Mon Jan 24, 2011 6:47 pm

need help with update

Post by ckdoublenecks »

This code clears the fields without executing the if statements ?

Code: Select all

<?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";
?>
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: need help with update

Post by Jonah Bron »

Not sure what you're asking/saying, but you're evaluating equality, not assigning those variables. Should be this:

Code: Select all

<?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";
?>
http://php.net/operators.comparison
http://php.net/operators.assignment
ckdoublenecks
Forum Newbie
Posts: 21
Joined: Mon Jan 24, 2011 6:47 pm

Re: need help with update

Post by ckdoublenecks »

Code: Select all

<?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";
?>
did the same
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: need help with update

Post by Jonah Bron »

Well, what were you expecting?
ckdoublenecks
Forum Newbie
Posts: 21
Joined: Mon Jan 24, 2011 6:47 pm

Re: need help with update

Post by ckdoublenecks »

I was expecting it to work after I followed your advice. Is that what you;re asking me?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: need help with update

Post by Jonah Bron »

No, I mean what do you expect the script to do? What do you want to happen, and what really happens? In what way does it fall short of your expectations?
Post Reply