2011-02-20 106 views
2

我有以下代碼。所有的值都被插入數據庫,而不是imaage字段。在數據庫中它是圖像中的「image」字段>代碼有什麼問題?等待你的回覆,謝謝你。在Mysql數據庫中上傳圖像

0) { echo「上傳錯誤」; } else { echo $ _FILES [「image」] [「name」]; move_uploaded_file($ _ FILES [「image」] [「tmp_name」],「images /".$_ FILES [」image「] [」name「]); $ con = mysql_connect(「localhost」,「root」,「319」);如果(!$ con) {012;}('Could not connect:'。mysql_error()); } mysql_select_db(「ju」,$ con);

 $sql="INSERT INTO teacher (tchr_name,tchr_degree,tchr_desig,tchr_email,tchr_phone,tchr_interest,image) 
     VALUES 
     ('$_POST[tchr_name]','$_POST[tchr_degree]','$_POST[tchr_desig]','$_POST[tchr_email]','$_POST[tchr_phone]','$_POST[tchr_interest]','$_FILES[image][name]')"; 

      if (!mysql_query($sql,$con)) 
      { 
      die('Error: ' . mysql_error()); 
      } 
      } 
     //echo "1 record added"; 
     mysql_close($con) 

?>

+0

看看另一個答案https://stackoverflow.com/questions/14535717/uploading-and-moving-image-files-on-web-server-image-not-uploaded/47366018#47366018 – antelove

回答

0

你確定圖像已被上傳好嗎?檢查錯誤字段$ _FILES ['image'] ['error']以確保上傳時沒有錯誤。或者嘗試執行$ _FILES數組的print_r以查看它是否包含所有信息。

+0

感謝Nicolas的回覆我剛剛解決了這個問題。 :)但新問題是我如何從我的數據庫中檢索特定的圖像?我可以使用用戶名或密碼作爲我想要打印圖像的人的關鍵?我必須在今天解決問題:(( – ratul

+0

)您應該使用標識該人的字段。也許電子郵件? – Nicolas