-1

Hi bro What erorr in this code Apper me this error

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of

<?php
   if(isset($_POST['addfile']))
     {

      $filename = $_POST['file_name'];// user name
      $filecat = $_POST['file_cat'];// user email
      $fileinfo = $_POST['file_info'];// user email
      $imgFile = $_FILES['file_photo']['name'];
      $tmp_dir = $_FILES['file_photo']['tmp_name'];
      $imgSize = $_FILES['file_photo']['size'];
      $urlFile = $_FILES['file_url']['name'];
      $tmp_dir = $_FILES['file_url']['tmp_name'];
      $urlSize = $_FILES['file_url']['size'];

      if(empty($filename)){
       $errMSG = "Please Enter file name.";
      }
      else if(empty($fileinfo)){
       $errMSG = "Please Enter file info.";
      }
      else if(empty($urlFile)){
       $errMSG = "Please Select File.";
      }
      else if(empty($imgFile)){
       $errMSG = "Please Select Image File.";
      }
      else
      {
       $upload_dir = 'share-admin/images/'; // upload directory

       $imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension

       // valid image extensions
       $valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions

       // rename uploading image
       $imgFile1 = rand(1000,1000000).".".$imgExt;

       // allow valid image file formats
       if(in_array($imgExt, $valid_extensions)){   
        // Check file size '5MB'
        if($imgSize < 5000000)    {
         move_uploaded_file($tmp_dir,$upload_dir.$imgFile1);
        }
        else{
         $errMSG = "Sorry, your file is too large.";
        }
       }
       else{
        $errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";  
       }

        $upload_dir = 'share-admin/files/'; // upload directory

       $urlExt1 = strtolower(pathinfo($urlFile,PATHINFO_EXTENSION)); // get image extension

       // valid image extensions
       $valid_extensions = array('zip', 'rar', 'pdf', 'doc'); // valid extensions

       // rename uploading image
       $urlFile1 = rand(1000,1000000).".".$urlExt1;

       // allow valid image file formats
       if(in_array($urlExt1, $valid_extensions)){   
        // Check file size '5MB'
        if($urlSize < 5000000)    {
         move_uploaded_file($tmp_dir,$upload_dir.$urlFile1);
        }
        else{
         $errMSG = "Sorry, your file is too large.";
        }
       }
       else{
        $errMSG = "Sorry, only zip, rar, pdf & doc files are allowed.";  
       }
      }


      // if no error occured, continue ....
      if(!isset($errMSG))
      {
          $db=getDB();
       $stmt = $db->prepare('INSERT INTO share_files(file_name,file_photo,file_url,file_date,file_cat,file_size,file_info) 
       VALUES(:filename,:imgFile1,:urlFile1,NOW(),:filecat,:$filesize,:fileinfo)');
       $stmt->bindParam(':filename',$filename);
       $stmt->bindParam(':filecat',$filecat);
       $stmt->bindParam(':fileinfo',$fileinfo);
       $stmt->bindParam(':imgFile1',$imgFile1);
       $stmt->bindParam(':urlFile1',$urlFile1);
       $stmt->bindParam(':$filesize',$urlSize);


       if($stmt->execute())
       {
        $successMSG = "new record succesfully inserted ...";
        header("refresh:5;addproject.php"); // redirects image view page after 5 seconds.
       }
       else
       {
        $errMSG = "error while inserting....";
       }
      }
     }

?>
Jhonwick
  • 5
  • 4

1 Answers1

0

That error typically indicates that there is an error in the INSERT statement - the number of fields does not match the number of values to be inserted.

Something doesn't look right about the $filesize parameter used in the INSERT statement. Not sure that is proper syntax. Does $filesize have a value elsewhere in the code that's not displayed in your example?

Cheryl Velez
  • 158
  • 8