How to determine if Update statement was successful

Before I can go further, I need to know why I’m getting that error. Can you explain?

Where are all your braces?

I don’t see where any further braces would go. Maybe that’s why I’m getting that “Can’t use function return value in write context” error in VS code at the arrow that I put in the code I posted.

Are these braces correct? I’m still getting that error.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0">
  <title>Foxclone backup, restore, and cloning utility</title>  
  <meta name="description" content= "FoxClone is a Linux based image backup, restore and clone tool using a simple point and click interface." />
  
    <link rel="stylesheet" type="text/css" media="screen" href="css/update.css"> 

    <!-- Favicon  -->
    <link rel="apple-touch-icon" sizes="180x180" href="images/favicon/apple-touch-icon.png">
    <link rel="icon" type="image/png" sizes="32x32" href="images/favicon/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="images/favicon/favicon-16x16.png">
    
    <link rel="mask-icon" href="images/favicon/safari-pinned-tab.svg" color="#5bbad5">
    <meta name="msapplication-TileColor" content="#da532c">
    <meta name="theme-color" content="#ffffff">

</head>

<body>
 
  <div class="container"> 
      <div class="row" style="text-align:center;" >
        <h1>Foxclone Filelist Updating</h1>
      </div>
         <div class="header"> </div>
<?php
  $chk=0;
  
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);


    function updater () {

    $php_scripts = '../php/';
    require $php_scripts . 'PDO_Connection_Select.php';
    
    if (!$pdo = PDOConnect("foxclone_data"))
    {	
      $chk=0;
        exit;
    }

        $meg = 1048576 ;  // needed to convert filesize bytes to Mb
        $stmt = $pdo->prepare("UPDATE `files` SET `filename` = ?, `md5` = ?, `filesize` = ?,`logtime` = now() WHERE `id` = ?") ;
        $path = 'download/';

        foreach(glob($path.'*.*') as $file) {
          $file = new SplFileInfo($path.$file);
          $extension  = $file->getExtension();          
              if (substr($file, 10,3) = "std") { //Errors with Can't use function return value in write context
                  $getdata = (array($file, md5_file($file), filesize($file)/$meg, 1)) ;
                  $count= $stmt->execute ($getdata) ; 
                     if ($count==0) 
                        exit("Failed to update std iso");}

              elseif (substr($file, 9,1) = "V"){
              $getdata = (array($file, md5_file($file), filesize($file)/$meg, 2)) ;
              $count= $stmt->execute ($getdata) ; 
                 if ($count==0) 
                    exit("Failed to update pdf"); }
                             
              elseif ($extension = "deb") {
              $getdata = (array($file, md5_file($file), filesize($file)/$meg,3)) ;         
              $count= $stmt->execute ($getdata) ; 
              if ($count==0) 
                   exit("Failed to update deb"); }
                                   
              elseif ($extension = "gz") {
              $getdata = (array($file, md5_file($file), filesize($file)/$meg,4)) ;
              $count= $stmt->execute ($getdata) ; 
              if ($count==0) 
                  exit("Failed to update gz"); }

              elseif (substr($file, 1,4) = "news") {
              $getdata = (array($file, md5_file($file), filesize($file)/$meg, 5)) ;
              $count= $stmt->execute ($getdata) ; 
              if ($count==0) 
                  exit("Failed to update news"); }
                                     
              elseif (substr($file(10,3) = "edg")) {
              $getdata = (array($file, md5_file($file), filesize($file)/$meg,6)) ;
              $count= $stmt->execute ($getdata) ; 
              if ($count==0) 
                  exit("Failed to update edge iso"); }
        
                         
        }
  }

    ?>
 <div class="row" style="text-align:center;" </div>   
    <h1>Database Update Successful</h1>





You are halfway there. Put them on each conditional

Still getting that error. Here’s the latest code:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0">
  <title>Foxclone backup, restore, and cloning utility</title>  
  <meta name="description" content= "FoxClone is a Linux based image backup, restore and clone tool using a simple point and click interface." />
  
    <link rel="stylesheet" type="text/css" media="screen" href="css/update.css"> 

    <!-- Favicon  -->
    <link rel="apple-touch-icon" sizes="180x180" href="images/favicon/apple-touch-icon.png">
    <link rel="icon" type="image/png" sizes="32x32" href="images/favicon/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="images/favicon/favicon-16x16.png">
    
    <link rel="mask-icon" href="images/favicon/safari-pinned-tab.svg" color="#5bbad5">
    <meta name="msapplication-TileColor" content="#da532c">
    <meta name="theme-color" content="#ffffff">

</head>

<body>
 
  <div class="container"> 
      <div class="row" style="text-align:center;" >
        <h1>Foxclone Filelist Updating</h1>
      </div>
         <div class="header"> </div>
<?php
  $chk=0;
  
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);


    function updater () {

    $php_scripts = '../php/';
    require $php_scripts . 'PDO_Connection_Select.php';
    
    if (!$pdo = PDOConnect("foxclone_data"))
    {	
      $chk=0;
        exit;
    }

        $meg = 1048576 ;  // needed to convert filesize bytes to Mb
        $stmt = $pdo->prepare("UPDATE `files` SET `filename` = ?, `md5` = ?, `filesize` = ?,`logtime` = now() WHERE `id` = ?") ;
        $path = 'download/';

        foreach(glob($path.'*.*') as $file) {
          $file = new SplFileInfo($path.$file);
          $extension  = $file->getExtension(); 
          $getdata = (array($file, md5_file($file), filesize($file)/$meg, $id)) ;
            if (substr($file, 10,3) = "std") { 
              $id = 1;

            }

            elseif (substr($file, 9,1) = "V"){
                $id = 2;
             }
                             
            elseif ($extension = "deb") {
                 $id = 3;
            }
                                   
              elseif ($extension = "gz") {
              $id = 4 ;
            }

              elseif (substr($file, 1,4) = "news") {
               $id = 5 ; 
            }
                                     
              elseif (substr($file(10,3) = "edg")) {
              $id =6;
            }
        
        $count= $stmt->execute ($getdata) ;                         
        }
  }

    ?>
 <div class="row" style="text-align:center;" </div>   
    <h1>Database Update Successful</h1>





Looks like you forgot what I told you earlier about the equals.

DUH!!! Fixed. Now why am I still getting that damn error saying “Can’t use function return value in write context” at the arrow in my code?

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0">
  <title>Foxclone backup, restore, and cloning utility</title>  
  <meta name="description" content= "FoxClone is a Linux based image backup, restore and clone tool using a simple point and click interface." />
  
    <link rel="stylesheet" type="text/css" media="screen" href="css/update.css"> 

    <!-- Favicon  -->
    <link rel="apple-touch-icon" sizes="180x180" href="images/favicon/apple-touch-icon.png">
    <link rel="icon" type="image/png" sizes="32x32" href="images/favicon/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="images/favicon/favicon-16x16.png">
    
    <link rel="mask-icon" href="images/favicon/safari-pinned-tab.svg" color="#5bbad5">
    <meta name="msapplication-TileColor" content="#da532c">
    <meta name="theme-color" content="#ffffff">

</head>

<body>
 
  <div class="container"> 
      <div class="row" style="text-align:center;" >
        <h1>Foxclone Filelist Updating</h1>
      </div>
         <div class="header"> </div>
<?php
  $chk=0;
  
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);


    function updater () {

    $php_scripts = '../php/';
    require $php_scripts . 'PDO_Connection_Select.php';
    
    if (!$pdo = PDOConnect("foxclone_data"))
    {	
      $chk=0;
        exit;
    }

        $meg = 1048576 ;  // needed to convert filesize bytes to Mb
        $stmt = $pdo->prepare("UPDATE `files` SET `filename` = ?, `md5` = ?, `filesize` = ?,`logtime` = now() WHERE `id` = ?") ;
        $path = 'download/';

        foreach(glob($path.'*.*') as $file) {
          $file = new SplFileInfo($path.$file);
          $extension  = $file->getExtension(); 
          $getdata = (array($file, md5_file($file), filesize($file)/$meg, $id)) ;
----->  if (substr($file, 10,3) == "std") { 
              $id == 1;
            }

            elseif (substr($file, 9,1) == "V"){
                $id == 2;
             }
                             
            elseif ($extension == "deb") {
                 $id == 3;
            }
                                   
              elseif ($extension == "gz") {
                   $id == 4 ;
            }

              elseif (substr($file, =1,4) = "news") {
                   $id == 5 ; 
            }
                                     
              elseif (substr($file(10,3) == "edg")) {
                   $id ==6;
            }
        
        $count= $stmt->execute ($getdata) ;
        IF ($count == 0) {
            echo("Failed to update ".$file);
        }
     }
  }

    ?>
 <div class="row" style="text-align:center;" </div>   
    <h1>Database Update Successful</h1>





I will say it one more time…

A single equals is an assignment
Two or three equals is a comparison.

I just put a sticky note on my monitor with that difference. Still get that error.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0">
  <title>Foxclone backup, restore, and cloning utility</title>  
  <meta name="description" content= "FoxClone is a Linux based image backup, restore and clone tool using a simple point and click interface." />
  
    <link rel="stylesheet" type="text/css" media="screen" href="css/update.css"> 

    <!-- Favicon  -->
    <link rel="apple-touch-icon" sizes="180x180" href="images/favicon/apple-touch-icon.png">
    <link rel="icon" type="image/png" sizes="32x32" href="images/favicon/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="images/favicon/favicon-16x16.png">
    
    <link rel="mask-icon" href="images/favicon/safari-pinned-tab.svg" color="#5bbad5">
    <meta name="msapplication-TileColor" content="#da532c">
    <meta name="theme-color" content="#ffffff">

</head>

<body>
 
  <div class="container"> 
      <div class="row" style="text-align:center;" >
        <h1>Foxclone Filelist Updating</h1>
      </div>
         <div class="header"> </div>
<?php
  $chk=0;
  
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);


    function updater () {

    $php_scripts = '../php/';
    require $php_scripts . 'PDO_Connection_Select.php';
    
    if (!$pdo = PDOConnect("foxclone_data"))
    {	
      $chk=0;
        exit;
    }

        $meg = 1048576 ;  // needed to convert filesize bytes to Mb
        $stmt = $pdo->prepare("UPDATE `files` SET `filename` = ?, `md5` = ?, `filesize` = ?,`logtime` = now() WHERE `id` = ?") ;
        $path = 'download/';

        foreach(glob($path.'*.*') as $file) {
          $file = new SplFileInfo($path.$file);
          $extension  = $file->getExtension(); 
          $getdata = (array($file, md5_file($file), filesize($file)/$meg, $id)) ;
----->  if (substr($file, 10,3) == "std") { 
              $id = 1;
            }

            elseif (substr($file, 9,1) == "V"){
                $id = 2;
             }
                             
            elseif ($extension == "deb") {
                 $id = 3;
            }
                                   
              elseif ($extension == "gz") {
                   $id = 4 ;
            }

              elseif (substr($file, 1,4) == "news") {
                   $id = 5 ; 
            }
                                     
              elseif (substr($file(10,3) == "edg")) {
                   $id =6;
            }
        
        $count = $stmt->execute ($getdata) ;
        IF ($count == 0) {
            echo("Failed to update ".$file);
        }
     }
  }

    ?>
 <div class="row" style="text-align:center;" </div>   
    <h1>Database Update Successful</h1>





Are you sure the value of $file is what you think it is?

Yes, I am. I changed that section of code from:

if (substr($file, 10,3) == "std") { 
              $id = 1;
            }

TO

          $test = substr($file, 10,3);
            if ($test == "std") {
              $id = 1;
            }

That eliminated the error without changing any of the elseif’s

What do you get with this?

$file = new SplFileInfo($path.$file);
var_dump($file);

I’m doing this in VS code. I haven’t actually run the code yet.

I just ran the code on my local server. It never showed the var_dump(). I wish there was a way to step thru the code as it runs.

put a die(); after it.

Tried it on multiple browsers. Never gets to the die(); Does it need the full path or can I use the relative path like I’m doing?

I gave it the full path but no change

I put code into the connection to tell me if it’s even connecting. Never see a fail or connect echo message.

$php_scripts = '../php/';
    require $php_scripts . 'PDO_Connection_Select.php';
    
    if (!$pdo = PDOConnect("foxclone_data"))     {	
        echo( 'Connection Failed');
       die() ;
    }
     else {
       echo('Connection made');
     }

PM me a zip of all the code including an SQL dump of your database.

I’ve got it echoing the filename, md5_sum, filesize, and id. The only problem now is that all the files end up with the same id.

I’m putting it down for the night. Will pick up after Dr. appointment in the morning. Thanks a lot for all the help.

Sponsor our Newsletter | Privacy Policy | Terms of Service