2015-05-07 48 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語句會響應查詢中的錯誤(如果有的話)

相關問題