data is not inserting in mysqli
I have an old mysql code where it successfully inserts the name of an image file into the database. But since old mysql is being decapitated, I have attempted doing the same in mysqli (can't use PDO because of version of PHP I have). The problem is that I cannot get the image file name to be inserted into the database in mysqli. What am I doing wrong?

Below is the mysqli code:


    <?php
    
    session_start();
    
    
    $username="xxx";
    $password="xxx";
    $database="mobile_app";
    
      $mysqli = new mysqli("localhost", $username, $password, $database);
    
      /* check connection */
      if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        die();
      }
    
    $result = 0;
    
    if( is_file("ImageFiles/".$_FILES['fileImage']['name'])) {
        $parts = explode(".",$_FILES['fileImage']['name']);
        $ext = array_pop($parts);
        $base = implode(".",$parts);
        $n = 2;
        
        while( is_file("ImageFiles/".$base."_".$n.".".$ext)) $n++;
        $_FILES['fileImage']['name'] = $base."_".$n.".".$ext;
        
        move_uploaded_file($_FILES["fileImage"]["tmp_name"],
        "ImageFiles/" . $_FILES["fileImage"]["name"]);
        $result = 1;
        
        $imagesql = "INSERT INTO Image (ImageFile) 
        VALUES (?)";
        
                if (!$insert = $mysqli->prepare($imagesql)) {
          // Handle errors with prepare operation here
        }
        
        $insert->bind_param("s",'ImageFiles/' . $_FILES['fileImage']['name']);
        
     $insert->execute();
    
            if ($insert->errno) {
              // Handle query error here
            }
            
            $insert->close();
    
        
    }
        else
          {
          move_uploaded_file($_FILES["fileImage"]["tmp_name"],
          "ImageFiles/" . $_FILES["fileImage"]["name"]);
          $result = 1;
          
        $imagesql = "INSERT INTO Image (ImageFile) 
        VALUES (?)";
        
                if (!$insert = $mysqli->prepare($imagesql)) {
          // Handle errors with prepare operation here
        }
        
        $insert->bind_param("s",'ImageFiles/' . $_FILES['fileImage']['name']);
        
     $insert->execute();
    
            if ($insert->errno) {
              // Handle query error here
            }
            
            $insert->close();
    
        
          }
    
    ?>
    

Below is the old mysql code where the insert did work:


    <?php
    
    session_start();
    
    
    $username="xxx";
    $password="xxx";
    $database="mobile_app";
    
    mysql_connect('localhost',$username,$password);
    
    mysql_select_db($database) or die( "Unable to select database");
    
    $result = 0;
    
    if( is_file("ImageFiles/".$_FILES['fileImage']['name'])) {
        $parts = explode(".",$_FILES['fileImage']['name']);
        $ext = array_pop($parts);
        $base = implode(".",$parts);
        $n = 2;
        
        while( is_file("ImageFiles/".$base."_".$n.".".$ext)) $n++;
        $_FILES['fileImage']['name'] = $base."_".$n.".".$ext;
        
        move_uploaded_file($_FILES["fileImage"]["tmp_name"],
        "ImageFiles/" . $_FILES["fileImage"]["name"]);
        $result = 1;
        
        $imagesql = "INSERT INTO Image (ImageFile) 
        VALUES ('ImageFiles/".mysql_real_escape_string($_FILES['fileImage']['name'])."')";
        
        mysql_query($imagesql);
        
    }
        else
          {
          move_uploaded_file($_FILES["fileImage"]["tmp_name"],
          "ImageFiles/" . $_FILES["fileImage"]["name"]);
          $result = 1;
          
    		$imagesql = "INSERT INTO Image (ImageFile) 
    		VALUES ('ImageFiles/".mysql_real_escape_string($_FILES['fileImage']['name'])."')";
    
    mysql_query($imagesql);
          
          }
          
          mysql_close();
    
    ?>
    
      <script language="javascript" type="text/javascript">
      window.top.stopImageUpload(<?php echo $result ? 'true' : 'false'; ?>, '<?php echo $_FILES['fileImage']['name'] ?>');
      </script>


data is not inserting in mysqli
===

I have an old mysql code where it successfully inserts the name of an image file into the database. But since old mysql is being decapitated, I have attempted doing the same in mysqli (can't use PDO because of version of PHP I have). The problem is that I cannot get the image file name to be inserted into the database in mysqli. What am I doing wrong?

Below is the mysqli code:


    <?php
    
    session_start();
    
    
    $username="xxx";
    $password="xxx";
    $database="mobile_app";
    
      $mysqli = new mysqli("localhost", $username, $password, $database);
    
      /* check connection */
      if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        die();
      }
    
    $result = 0;
    
    if( is_file("ImageFiles/".$_FILES['fileImage']['name'])) {
        $parts = explode(".",$_FILES['fileImage']['name']);
        $ext = array_pop($parts);
        $base = implode(".",$parts);
        $n = 2;
        
        while( is_file("ImageFiles/".$base."_".$n.".".$ext)) $n++;
        $_FILES['fileImage']['name'] = $base."_".$n.".".$ext;
        
        move_uploaded_file($_FILES["fileImage"]["tmp_name"],
        "ImageFiles/" . $_FILES["fileImage"]["name"]);
        $result = 1;
        
        $imagesql = "INSERT INTO Image (ImageFile) 
        VALUES (?)";
        
                if (!$insert = $mysqli->prepare($imagesql)) {
          // Handle errors with prepare operation here
        }
        
        $insert->bind_param("s",'ImageFiles/' . $_FILES['fileImage']['name']);
        
     $insert->execute();
    
            if ($insert->errno) {
              // Handle query error here
            }
            
            $insert->close();
    
        
    }
        else
          {
          move_uploaded_file($_FILES["fileImage"]["tmp_name"],
          "ImageFiles/" . $_FILES["fileImage"]["name"]);
          $result = 1;
          
        $imagesql = "INSERT INTO Image (ImageFile) 
        VALUES (?)";
        
                if (!$insert = $mysqli->prepare($imagesql)) {
          // Handle errors with prepare operation here
        }
        
        $insert->bind_param("s",'ImageFiles/' . $_FILES['fileImage']['name']);
        
     $insert->execute();
    
            if ($insert->errno) {
              // Handle query error here
            }
            
            $insert->close();
    
        
          }
    
    ?>
    

Below is the old mysql code where the insert did work:


    <?php
    
    session_start();
    
    
    $username="xxx";
    $password="xxx";
    $database="mobile_app";
    
    mysql_connect('localhost',$username,$password);
    
    mysql_select_db($database) or die( "Unable to select database");
    
    $result = 0;
    
    if( is_file("ImageFiles/".$_FILES['fileImage']['name'])) {
        $parts = explode(".",$_FILES['fileImage']['name']);
        $ext = array_pop($parts);
        $base = implode(".",$parts);
        $n = 2;
        
        while( is_file("ImageFiles/".$base."_".$n.".".$ext)) $n++;
        $_FILES['fileImage']['name'] = $base."_".$n.".".$ext;
        
        move_uploaded_file($_FILES["fileImage"]["tmp_name"],
        "ImageFiles/" . $_FILES["fileImage"]["name"]);
        $result = 1;
        
        $imagesql = "INSERT INTO Image (ImageFile) 
        VALUES ('ImageFiles/".mysql_real_escape_string($_FILES['fileImage']['name'])."')";
        
        mysql_query($imagesql);
        
    }
        else
          {
          move_uploaded_file($_FILES["fileImage"]["tmp_name"],
          "ImageFiles/" . $_FILES["fileImage"]["name"]);
          $result = 1;
          
    		$imagesql = "INSERT INTO Image (ImageFile) 
    		VALUES ('ImageFiles/".mysql_real_escape_string($_FILES['fileImage']['name'])."')";
    
    mysql_query($imagesql);
          
          }
          
          mysql_close();
    
    ?>
    
      <script language="javascript" type="text/javascript">
      window.top.stopImageUpload(<?php echo $result ? 'true' : 'false'; ?>, '<?php echo $_FILES['fileImage']['name'] ?>');
      </script>

