2015-05-07 47 views
1

我试图执行此代码,但我的代码因为某些原因无法插入表中而死亡。给出的错误是“存储到表时出错”我有查看我的代码,但不能看到我的PDO插入到查询或php错误日志中有任何问题。PDO查询没有插入,也没有错误

try { 
     $result = $s3->putObject([ 
       'Bucket' => $config['s3']['bucket'], 
       'Key' => "uploads/{$name_of_uploaded_file}", 
       'Body' => fopen($path_of_uploaded_file, 'rb'), 
       'ACL' => 'public-read' 
      ]); 

      if (is_uploaded_file($_FILES['uploaded_file']['size'])){ 
        //send items to pending database 

        //inserts in pending db 
        $sql = "INSERT INTO pending (id,photo,title,description,name,pLike,pDislike) VALUES ('', :photo, :title, :description, :name, :pLike, :pDislike)"; 
        $stmt = $conn->prepare($sql); 
        $stmt->bindParam(':title', $title); 
        $stmt->bindParam(':photo', $result); 
        $stmt->bindParam(':description', $story); 
        $stmt->bindParam(':name', $first_name); 
        $stmt->bindValue(':pLike', 0, PDO::PARAM_INT); 
        $stmt->bindValue(':pDislike', 0, PDO::PARAM_INT); 
        $stmt->execute();  
      }else { 
       die("there was an error in storing to table");   
      } 

     //remove the file 
      unlink($path_of_uploaded_file); 
    } catch(S3Exception $e){ 
     die("there was an error"); 
    } 

回答

3

它已经在manual说:

Returns TRUE if the file named by filename was uploaded via HTTP POST.

For proper working, the function is_uploaded_file() needs an argument like

$_FILES['userfile']['tmp_name'] ,

the name of the uploaded file on the client's machine $_FILES['userfile']['name'] does not work.

现在,你指向的size指数:

is_uploaded_file($_FILES['uploaded_file']['size'] 
             //^

应该是:

if (is_uploaded_file($_FILES['uploaded_file']['tmp_name'])){ 
+0

ok了第一部分,所以我改变了你什么建议,但它给了我这个错误:在空上调用一个成员函数准备()这是因为(is_uploaded_file($ _ FILES ['uploaded_file'] ['tmp_name']))为空? – Gianni

+0

你知道我在mypart上有一个新人的错误。准备应该是pdo而不是conn。对不起,并非常感谢帮助我澄清 – Gianni

+0

@ user4589398哦,所以它支持'$ pdo' lol:D错字。很高兴这有帮助 – Ghost

1
try{ 
        $sql = "INSERT INTO pending (id,photo,title,description,name,pLike,pDislike) VALUES ('', :photo, :title, :description, :name, :pLike, :pDislike)"; 
        $stmt = $conn->prepare($sql); 
        $stmt->bindParam(':title', $title); 
        $stmt->bindParam(':photo', $result); 
        $stmt->bindParam(':description', $story); 
        $stmt->bindParam(':name', $first_name); 
        $stmt->bindValue(':pLike', 0, PDO::PARAM_INT); 
        $stmt->bindValue(':pDislike', 0, PDO::PARAM_INT); 
        $stmt->execute();  
} 
catch(PDOException $e){ 
echo 'error in query: '.$e->getMessage(); 
} 

在你的if语句会响应查询中的错误(如果有的话)

相关问题