dongyupan4850 2010-04-27 16:37
浏览 85
已采纳

通过表单将内容输入MySQL数据库

I've been working on creating a form that submits content into my database but I decided that rather than using a drop down menu to select the date I'd rather use a textfield. I was wondering what changes I will need to make to my table creation file.

<?php mysql_connect ('localhost', 'root', 'root') ;
mysql_select_db ('tmlblog');

$sql = "CREATE TABLE php_blog (
  id int(20) NOT NULL auto_increment,
  timestamp int(20) NOT NULL,
  title varchar(255) NOT NULL,
  entry longtext NOT NULL,
  PRIMARY KEY  (id)
)";

$result = mysql_query($sql) or print ("Can't create the table 'php_blog' in the database.<br />" . $sql . "<br />" . mysql_error());

mysql_close();
if ($result != false) {
    echo "Table 'php_blog' was successfully created.";
}
?>

It's the timestamp that I need to edit to enter in via a textfield. The Title and Entry are currently being entered via that method anyway.

Whenever I use my form to update the database I get the following error message:

Can't insert into table php_blog. INSERT INTO php_blog (time_stamp,title,entry,) VALUES ('1270140960','kjkkj','jkjkjk') You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') VALUES ('1270140960','kjkkj','jkjkjk')' at line 1

  • 写回答

5条回答 默认 最新

  • duanruanxian5028 2010-04-27 16:46
    关注

    TIMESTAMP is a reserved MySQL word. You will need to place backticks around it if you wish to use it as a field name. However, I recommend changing it.

    You should also make it a DATE or DATETIME field as that's the kind of data you're actually storing in it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块