PHP syntax?

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
ckir5951
Forum Newbie
Posts: 1
Joined: Thu Jul 23, 2015 5:32 pm

PHP syntax?

Post by ckir5951 »

Hi, I have checked the validity of the table and in
all 3 records "recur" ='Y', "payrec" ='p', values are in "duedate",
"datepaid" (type is DATE) and "periodic". I'm looping thru the data; var_dump() displays NULL NULL NULL, It seems that my DATEDIFF is flawed.
I've spent considerable time viewing forums, manuals, code types. How about some advice?

Code: Select all

<?php
error_reporting(E_ALL ^ E_NOTICE);
// error_reporting(0);
$servername = "localhost"; $username = "root";
$password = "cookie"; $dbname = "test";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
   { die("Connection failed: " . $conn->connect_error); }
// ==================================================
$sql = "SELECT recur, periodic, pd, payrec, duedate, datepaid,
DATEDIFF(CURDATE(),duedate) AS dayslate
FROM testbl WHERE recur = 'Y' && payrec = 'P'";
$result = $conn->query($sql);
if ($result->num_rows > 0)
 {
    // output data of each row
    while($row = $result->fetch_assoc()) // ****3 records *****
 {
    // ***************************************************
    var_dump($dayslate); // NULL NULL NULL 
   // ***************************************************
    if ($dayslate > 0)
 { 
    if($dayslate > 120)
    {$pastdue = "PAST DUE";}

    if($periodic == 1)
           { $duedate = date('Y-m-d', strtotime('+4 week')) ."\n"; }
    if($periodic == 6)
           { $duedate = date('Y-m-d', strtotime('+25 week')) ."\n"; }
$pd = 'P'; $daylate = 0;
// ==================================================
$sql = "UPDATE testbl SET
        pd = '$pd',
   duedate = '$duedate',                      
 $datepaid = 'NOW()',
  dayslate = '$dayslate'
 WHERE dayslate = 0";
if ($conn->query($sql) === TRUE)
    { echo "Record updated successfully"; } 
    else
    { echo "Error updating record: " . $conn->error; }

$conn->close(); 
 }
  }
 }
 // header( "refresh:3;url='http://localhost/invoice/autolist.php'");
?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP syntax?

Post by Celauran »

You're fetching an associative array into $row. Try $row['dayslate'] instead of $dayslate.
Post Reply