首页 > 解决方案 > 使用 mysqli 方法和文件函数将 html 表单资源存储到 mySQL 中时遇到问题

问题描述

在表单之前运行的 PHP

<?php
error_reporting(E_ALL);
ini_set('display_errors',1);

include 'config.php';
include 'pageblocks.php';
include 'functions.php';

if ( isset( $_POST ) && ! empty( $_FILES ) ) {
  echo upload_file();

  echo '1';
  $stmt = $conn->prepare("INSERT INTO art_content (headline, content_type, postdate, title,
  content, index_thumb) VALUES (?,?,?,?,?,?)");
  echo '2';
  $stmt->bind_param('ssssss', $_POST['headline'],
  $_POST['content_type'], $_POST['postdate'], $_POST['title'], $_POST['content'],
    $_POST['file']);
  echo '3';
  $stmt->execute();
  echo '4';
  $conn->close();
  unset($_POST);
}

metablock('content upload page');
headerblock('');
?>

我试图在现场实施的表格

<form method ="post" action="" enctype="multipart/form-data">
  <label for="headline"><strong>Choose Index Headline</strong></label><br><br>
  <select name="headline">
    <option value="addition to gallery">addition to gallery</option>
    <option value="new patron content">new patron content</option>
    <option value="new youtube video">new youtube video</option>
    <option value="new addition to articles">new addition to articles</option>
  </select><br><br>

  <label for="content_type"><strong>Choose content type:</strong></label><br><br>
  <select name="content_type">
    <option value="digital photograph">digital photograph</option>
    <option value="digital painting">digital painting</option>
    <option value="traditional painting">traditional painting</option>
    <option value="twitch branding">twitch branding</option>
    <option value="article">article</option>
  </select><br><br>

  <label><strong>post date</strong></label><br><br>
  <input name="postdate" type="text"><br><br>

  <label><strong>title</strong></label><br><br>
  <input name="title" type="text"><br><br>

  <label><strong>text content</strong></label><br><br>
  <textarea name="content" type="text"></textarea><br><br>

  <input type="file" name="file">
  <input type="submit" value="Upload">
</form>

我的上传文件功能工作正常,但 MySQL 数据似乎没有进入服务器。我不知道该怎么做,正在考虑尝试 PDO 方法,因为它看起来不那么令人困惑,但放弃 mysqli 方法来连接感觉不好

标签: phphtmlmysql

解决方案


推荐阅读