插入并从数据库中选择

时间:2014-07-18 13:58:27

标签: php mysql sql

我的查询有问题。问题是:文件已正确加载到uploads文件夹中。但不在具有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。

对不起我的英语不好,我不能说得很好。

1 个答案:

答案 0 :(得分: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语句中的“I”

问候