Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mysql php与上传文件插入记录到数据库_Php_Mysql_Sql - Fatal编程技术网

mysql php与上传文件插入记录到数据库

mysql php与上传文件插入记录到数据库,php,mysql,sql,Php,Mysql,Sql,我做错了什么,除了不能将文件名插入数据库外,其他一切都正常。它确实传递了所有信息,但它不传递文件我知道它与插入有关 这是我的插入代码 if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "file_upload")) { $insertSQL = sprintf("INSERT INTO products_tbl (`first`, image , pro_name, pro_desc, price

我做错了什么,除了不能将文件名插入数据库外,其他一切都正常。它确实传递了所有信息,但它不传递文件我知道它与插入有关

这是我的插入代码

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "file_upload")) {
  $insertSQL = sprintf("INSERT INTO products_tbl (`first`, image , pro_name, pro_desc,      price) VALUES (%s, %s, %s, %s, %s)",
                   GetSQLValueString($_POST['first'], "text"),
                   GetSQLValueString($_POST['image'], "text"),
                   GetSQLValueString($_POST['pro_name'], "text"),
                   GetSQLValueString($_POST['pro_desc'], "text"),
                   GetSQLValueString($_POST['price'], "text"));
这是我的表格代码

<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" id="file_upload">
      <table width="624">
        <tr valign="baseline">
          <td align="right">First:</td>
          <td><input type="text" name="first" value="" size="50" /></td>
        </tr>
        <tr valign="baseline">
          <td align="right"><label>Select File: </label></td>
          <td><div class='input file'>

                <input type='file' name='file[]' id='file[]'/>
                <a href='#' class='add_another_file_input hide'>
                    <img src='../img/add.png' alt='Add Icon' />
                </a>
            </div></td>
        </tr>
        <tr valign="baseline">
          <td align="right">Service Name:</td>
          <td><input name="pro_name" type="text" value="" size="50" /></td>
        </tr>
        <tr valign="baseline">
          <td align="right">Service Description:</td>
          <td><textarea name="pro_desc" cols="50" rows="10"></textarea></td>
        </tr>
        <tr valign="baseline">
          <td align="right">Price:</td>
          <td><input type="text" name="price" value="" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td align="right">&nbsp;</td>
          <td><div class='input buttons'>
                <input name='upload' type='submit' id='upload' value="Upload"></button>
            </div></td>
        </tr>
      </table>
      <input type="hidden" name="MM_insert" value="file_upload" />
      <?php //pr($upload); ?>


除了不能将文件名插入数据库外,其他一切都正常。

字符串周围缺少引号

$insertSQL = sprintf("INSERT INTO products_tbl (`first`, image , pro_name, pro_desc,      price) 
VALUES (%s, %s, %s, %s, %s)",
应该是:

$insertSQL = sprintf("INSERT INTO products_tbl (`first`, image , pro_name, pro_desc,      price) 
VALUES ('%s', '%s', '%s', '%s', '%s')",

除了文件[],所有内容都会发送到数据库。我希望将文件[]名称发送到“图像”所在的数据库。该代码完成了我需要的所有其他操作,它在数据库中插入infomration,除了文件[]中的“image”,它还将图像放入我指定的文件夹,并正确上载图像。它只是不将文件名发送到数据库。