0
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中没有插入数据。请协助..非常感谢您的帮助!

4

3 回答 3

0

也许这会有所帮助

$query="INSERT INTO uploads(file_name,file_size,file_type,description)VALUES('".$_FILES['image']['name']."',".$_FILES['image']['size'].",'".$_FILES['image']['type']."','".$d."')";
于 2013-07-17T12:36:08.567 回答
-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 执行查询。

于 2013-07-17T12:35:53.657 回答
-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());;
于 2013-07-17T12:35:59.360 回答