Home >Backend Development >PHP Tutorial > 交付后不能向数据库插入数据

交付后不能向数据库插入数据

WBOY
WBOYOriginal
2016-06-13 13:09:05781browse

提交后不能向数据库插入数据
conn.php

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><?php $conn = @ mysql_connect("localhost", "root", "root") or die("数据库链接错误");
   mysql_select_db("bbs", $conn);
   mysql_query("set names 'GBK'"); //使用GBK中文编码;

?>


add.php
PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><?php include("conn.php");

   if($_POST['submit']){
   
     $sql="insert into message (id,user,title,content,lastdate) 
     values ('','$_POST[user]','$_POST[title]','$_POST[content]',now())";
   
   mysql_query($sql);
   echo "发表成功";
   }

?>

用户:
标题:
内容:




点击发表留言后在数据库找到记录,是代码有问题吗?

------解决方案--------------------
mysql_query($sql) or die(mysql_error()); //这样报错了没有
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article: PHP分页种 Next article: php安全有关问题大总结