你好兄弟在这段代码中有什么erorr给我这个错误
致命错误:未捕获的异常' PDOException'消息' SQLSTATE [HY093]:参数号无效:绑定变量数与
的数量不匹配<?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....";
}
}
}
?>
答案 0 :(得分:0)
该错误通常表示INSERT语句中存在错误 - 字段数与要插入的值数不匹配。
INSERT语句中使用的$ filesize参数看起来不对。不确定这是正确的语法。 $ filesize在代码中的其他地方是否有值,但在示例中没有显示?