mysql php 上传文件插入记录到数据库 [英] mysql php with upload file insert record to database

查看:42
本文介绍了mysql php 上传文件插入记录到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做错了什么,一切正常,只是它不会将文件名插入到数据库中.它确实通过了所有内容,但它不执行我知道它与插入有关的文件.

What am I doing wrong, everything works except it will not insert the file name into the database. It does pass everything but it does not do the file I know it has something to do with the insert.

这是我的插入代码

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); ?>

除了不将文件名插入数据库之外,一切正常.

Everything works except it does not insert the file name into the database.

推荐答案

您的字符串周围缺少引号.

You're missing quotes around your strings.

$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')",

这篇关于mysql php 上传文件插入记录到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆