无法插入任何记录并返回错误:MySQL返回空结果集(即零行)

时间:2013-07-17 12:31:54

标签: php mysql

if(isset($_POST['submitted']))
{
   //mysql_connect('localhost','root','')or die(mysql_error());
   //mysql_select_db('ecommerce');
   include_once ('mysql_connect.php');
   if(is_uploaded_file($_FILES['image']['tmp_name']))
   {
      // $image=$_FILES['image']['tmp_name'];
       if(move_uploaded_file($_FILES['image']['tmp_name'], "uploads/".$_FILES['image']['name']))
       {
          if(!empty($_POST['description']))
          {
              $d=$_POST['description'];
          }
          else
          {
             $d=NULL;
          }
          $query="INSERT INTO uploads(file_name,file_size,file_type,description)VALUES('{$_FILES['image']['name']}',{$_FILES['image']['size']},'{$_FILES['image']['type']}',$d)"
                or die(mysql_error());
          mysql_query($query);
       }
   }
}

**数据库连接没有错误。图片也成功保存在文件夹中但没有数据插入mysql。请帮助..非常感谢您的帮助!

3 个答案:

答案 0 :(得分:0)

也许这会有所帮助

$query="INSERT INTO uploads(file_name,file_size,file_type,description)VALUES('".$_FILES['image']['name']."',".$_FILES['image']['size'].",'".$_FILES['image']['type']."','".$d."')";

答案 1 :(得分:-1)

$query="INSERT INTO uploads(file_name,file_size,file_type,description)VALUES('{$_FILES['image']['name']}',{$_FILES['image']['size']},'{$_FILES['image']['type']}','$d')";
mysql_query($query) or die(mysql_error());

我假设您的description字段不仅仅采用整数。在字符串中插入单引号插入数据库。

mysql_query也已弃用。使用mysqli或pdo执行查询。

答案 2 :(得分:-2)

$query="INSERT INTO uploads(file_name,file_size,file_type,description)VALUES('{$_FILES['image']['name']}',{$_FILES['image']['size']},'{$_FILES['image']['type']}', '$d')"
mysql_query($query) or die(mysql_error());;