2014-07-18 164 views
-1

我的查詢存在問題。問題是:該文件已正確加載到上傳文件夾中。但是不能在textarea內容的數據庫中。插入並從數據庫中選擇

我已經創建了此表到我的數據庫有:

CREATE TABLE dati(article VARCHAR(30), photo VARCHAR(30)) 

這是我的代碼(從互聯網上挑選)

<?php 
//This is the directory where images will be saved 

$target = "../image/"; 
if(isset($_FILES['photo']['name'])) { 
$target = $target . basename($_FILES['photo']['name']); 
//This gets all the other information from the form 
} 
$article = (isset($_POST['article'])); 
$pic = (isset($_FILES['photo']['name'])); 

// Connects to your Database 

//Writes the information to the database 
if (isset($_FILES['photo']['name'])) if (isset($_POST['article'])) { 
mysql_query("INSERT INTO nome_tabella (photo, article) VALUES ('{$_FILES['photo']['name']}', '{$_POST['article']}'"); 
} 
//Writes the photo to the server 
    if(isset($_FILES['photo']['tmp_name'])) 
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
{ 


//Tells you if its all ok 
echo "The file ". basename(isset($_FILES['uploadedfile']['name'])). " has been uploaded, and your information has been added to the directory"; 
} 
else { 

//Gives and error if its not 
echo "Sorry, there was a problem uploading your file."; 
} 
?> 

我試了好幾次,但沒有將數據插入到數據庫。怎麼了?

這是代碼讀取結果

<?php 
    //Retrieves data from MySQL 
    $data = mysql_query("SELECT * FROM 'dati' (photo, article)") or die(mysql_error()); 
    while($info = mysql_fetch_array($data)) { 
    echo "<div id='cover'>"; 
    echo "<img src='http://localhost/chiedifilm/image/".$info['photo']. "'>"; 
    echo "</div>"; 
    echo "" .$info['article']. ""; 
    echo "<hr>"; } ?> 

這不加載圖像名稱和textarea的TinyMCE的。

對不起,我的英語不好,我不會說得很好。

+3

'( 「NSERT INTO nome_tabella'缺少'I' - '(」 INSERT INTO nome_tabella' - 錯字?這是你的代碼中的錯誤之一。約翰向你展示了其他錯誤。 –

+2

你的選擇語句不正確,它有多個錯誤,試試:'SELECT photo,article FROM dati' –

+0

+1 ...是的,發現@JohnConde後引號等等等。 –

回答

0

檢查你的代碼:

//Writes the information to the database 
if (isset($_FILES['photo']['name'])) if (isset($_POST['article'])) { 
mysql_query("**NSERT** INTO nome_tabella (photo, article) VALUES ('{$_FILES['photo']['name']}', '{$_POST['article']}'"); 
} 

這裏的 「我」 在INSERT語句

問候

+0

我已經改正了錯誤,但沒有奏效...... – SardaFilm

相關問題