How to determine if Update statement was successful

Well, you handle IF’s loosely like this:

if (condition) {
   //  Do something...  When condition is true
} else {
   //  Do something else...  When condition fails
}
if (condition1) {    //  nested if's
   //  Do condition true stuff...
   if(condition2) {
        //  do secondary possible code...
    } else {
        //  Still inside true condition 1, do other false stuff for condition 2
    }
} else {
   //  do condition1 false stuff...
}

Your code is messy. You ASSIGN a substr which is not possible. “=” means ASSIGN “==” means compare or actually IF-EQUAL-TO. I will guess you meant to use ==… But, it is very hard to follow your code as you do not use paren’s much… { } They group code to run when the results of a condition false or true. You have just a pile of run-on code. Hard to read and very hard to debug…

But, my guess is a spelling error … == not = …

Thanks to everyone who helped. I have it working properly although I’m not happy with all the if statements. Here’s the code that’s working:


<?PHP require_once("up_header.php"); ?>
</head>
<body>
 
 <div class="container"> 
     <div class="row" style="text-align:center;" >
       <h1>Foxclone Filelist Updating</h1>
     </div>
     <div class="header">
 </div>   
<?php
 
  
    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"))     {	
        echo( 'Connection Failed');
    }
    
        $meg = 1048576 ;  // needed to convert filesize bytes to Mb
        $stmt = $pdo->prepare("UPDATE `files` SET `filename` = ?, `md5` = ?, `filesize` = ?,`logtime` = now() WHERE `id` = ?") ;
        $path = 'download/';  
        $id = NULL;
        $filename = '';

        foreach(glob($path.'*.*') as $file) {
          $id = NULL; 
          $filename = basename($file) ;
          $file = new SplFileInfo($file);
          $extension  = $file->getExtension(); 
          $test = substr($filename, 0,12);
            if ($test == 'foxclone_std') {
                $id = 1;
            }

          if (substr($filename, 0,9) == "foxcloneV"){
                $id = 2;
             }
                             
          if ($extension == "deb") {
                 $id = 3;
            }
                                   
          if ($extension == "gz") {
                   $id = 4 ;
            }

          if (substr($filename, 0,4) == "news") {
                   $id = 5 ; 
            }
                                     
          if (substr($filename, 0,13) == "foxclone_edge") {
                   $id =6;
            }
            $getdata = (array($filename, md5_file($file), filesize($file)/$meg, $id)) ;
            
            $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>

Sponsor our Newsletter | Privacy Policy | Terms of Service