Home >Backend Development >PHP Tutorial >初学者 从前台表单获取值输入数据库中

初学者 从前台表单获取值输入数据库中

WBOY
WBOYOriginal
2016-06-13 10:09:121364browse

菜鸟求助 从前台表单获取值输入数据库中

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$db=mysql_connect('localhost','root','','news1');$query="insert into news (title,author,datetime,content)values('$title','$author','$datetime','$content')";        $result=mysql_query($query);if($result){    echo mysql_affected_rows()."row(s) insert into database.";}else{    echo "An error has occurred.The item was not added.";}


输入相关的值之后,输出的结果总是An error has occurred.The item was not added 是什么原因应该怎么修改呢?

谢谢~



------解决方案--------------------
mysql_connect('localhost','root','');

mysql_select_db('news1')
------解决方案--------------------
mysql_connect 和 mysqli_connect参数用法不一样的 不能指定数据库

你翻手册看看,
------解决方案--------------------
$db=mysql_connect('localhost','root','') or die('数据库连服务器接失败');
mysql_select_db('news1', $db) or die ('数据库连接失败');
........
------解决方案--------------------
$query="insert into news (title,author,datetime,content)values('$title','$author','$datetime','$content') or die(mysql_error())";

看看提示什么。
------解决方案--------------------
这种问题。。。第一时间输出sql。。。
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