php表单不将日期保存到数据库中

标签 php mysql database forms insert

我的问题是我有一个表单应该将漫画书的信息保存到数据库中,它保存的信息是标题、描述等,它还将漫画的图像上传到我的服务器。

现在它确实将图像上传到服务器,但它没有将任何信息放入我的表中,简单不知道为什么?

我对 php 和 mysql 很陌生,所以也许这是一个简单的问题,但我无法弄清楚这一点,而且我无法在网上找到答案。

我的表结构:

  1. id - int(11)
  2. 标题 - varchar(50)
  3. 描述 - 文本
  4. 公众 - varchar(50)
  5. 图像 - varchar(30)
  6. 价格 - int(10)
  7. 状态 - tinyint(1)

我的表单位于我的index.php 上,如下所示:

<form method="post" action="newcomic.php" enctype="multipart/form-data">
<p>Comic name:
<br><input type="text" name="title"/></p>

<p>Description of the comic:
<br><textarea name="description"></textarea></p>

<p>Publicer:
<br><input type="text" name="publicer" /></p>

<p>Image:
<br><input type="file" name="image" /></p> 

<p>Price:
<br><input type="text" name="price" /></p>

<p><input type="submit" name="add" title="Add new comic to database" value="Add Comic"/></p>
</form>

我的 newcomic.php 文件看起来像这样

<?php

//This is the directory where images will be saved
$target = "images/";
$target = $target . basename( $_FILES['image']['name']);

//This gets all the other information from the form
$title = $_POST['title'];
$description = $_POST['description'];
$publicer = $_POST['publicer'];
$image = ($_FILES['image']['name']);
$price = $_POST['price'];


// Connects to your Database
mysql_connect("localhost", "root", "root") or die(mysql_error()) ;
mysql_select_db("comic_express") or die(mysql_error()) ;

//Writes the information to the database
mysql_query("INSERT INTO products (id, title, description, publicer, image, price, status)
VALUES ('', '$title', '$description', '$publicer', '$image', '$price', '1')") ;

//Writes the photo to the server
if(move_uploaded_file($_FILES['image']['tmp_name'], $target)) {

//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>

希望有人能帮助我:)

最佳答案

sql 语法错误。您正在尝试将空字符串放入 id 中。

关于php表单不将日期保存到数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20254255/

相关文章:

PHP Memcached 客户端 - 设置数据时压缩不起作用

java - 哪种数据库和编码方案适合音频数据存储?

mysql - 从条件只影响一个表的两个表中选择

MySQL Workbench 无法在 Windows 8.1 上运行

python - 基于单个输入分配多个值的大多数 pythonic 方法

android - GreenDao无法设置数据库

php - 在 CodeIgniter 中路由所有 URL 请求?

php - 每 x 天/月/年执行脚本内的任务,具体取决于 db 值

php - MySql 结果显示 id 号而不是单词

mysql - 提高连接性能