-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的。
对不起,我的英语不好,我不会说得很好。
'( “NSERT INTO nome_tabella'缺少'I' - '(” INSERT INTO nome_tabella' - 错字?这是你的代码中的错误之一。约翰向你展示了其他错误。 –
你的选择语句不正确,它有多个错误,试试:'SELECT photo,article FROM dati' –
+1 ...是的,发现@JohnConde后引号等等等。 –