0

Why is this code note updating the database????

<?php

include '../connection.php';

    $today = new DateTime('2014-7-14 20:10:10');
    $appt  = new DateTime('2014-8-15 20:10:10');
    $days_until_appt = $appt->diff($today)->days;


if ($days_until_appt>=30)
{

    $sql = "SELECT username FROM users WHERE position = 'Tenant'";
    $result = mysql_query($sql) or die(mysql_error());

    echo '<table align="center" border="1" cellpadding="0">';
    echo '<tr align="center"><th> Payee'.'</th><th> Credit'.'</tr>';

    while($row = mysql_fetch_array($result))
    {
    echo '<tr><th>'.$row['username'].'</th>'.'<br/>';
    $rw = $row['username'];

    $sq = "SELECT * FROM finance WHERE payee = '$rw'";
    $res = mysql_query($sq) or die(mysql_error());
    $rew = mysql_fetch_array($res);

    $r = $rew['credit'] +=  3000 ;

    $s="UPDATE finance SET credit ='" . $r. "'  WHERE payee = 'rw'";
    mysql_error();


    echo '<th>'.$r.'</th></tr>'.'<br/>';
    }
    echo'</table>';
}
?>
4
Contributors
4
Replies
26
Views
3 Years
Discussion Span
Last Post by DJBirdi
1

You never execute the update query

$s="UPDATE finance SET credit ='" . $r. "'  WHERE payee = 'rw'";
$res = mysql_query($s) or die(mysql_error());
0

Thats not the reason because its still not updating the database

0
<?php
    // will NOT update since there is no "payee" named "rw"
    // because "rw" is supposed to be a variable
    // so change payee = 'rw' to payee = '$rw'

    $s="UPDATE finance SET credit ='" . $r. "'  WHERE payee = 'rw'";    
    $res = mysql_query($s) or die(mysql_error());
?>

Edited by DJBirdi

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.