conn.php内容:
<?php
$conn = @ mysql_connect("localhost", "root", "") or die("数据库链接错误");
mysql_select_db("bbs", $conn);
mysql_query("set names 'GBK'"); //使用GBK中文编码;
?>
add.php内容:<?php
include("conn.php");if($_post['submit']){
$sql="insert into message (id,user,title,content,lastdate) value ('','$_post[user]','$_post[title]','$_post[content]',now())";
mysql_query($sql);
echo"发表成功";
}?>
<form action="add.php" method="post">
用户:<input type="text" name="user" /><br/>
标题:<input type="text" name="title" /><br/>
内容:<textarea name="content"></textarea><br/>
<input type="submit" name="submit" value="发布留言" />
</form>
我看php100视频写的代码,但是我运行后,数据库里面没有添加到纪录,而且页面没有任何提示,也无反应。
我用的是wamp,mysql已经运行了,测试也连接到数据库了,就是不知道为什么提交按钮后,没有反应。
<?php
$conn = @ mysql_connect("localhost", "root", "") or die("数据库链接错误");
mysql_select_db("bbs", $conn);
mysql_query("set names 'GBK'"); //使用GBK中文编码;
?>
add.php内容:<?php
include("conn.php");if($_post['submit']){
$sql="insert into message (id,user,title,content,lastdate) value ('','$_post[user]','$_post[title]','$_post[content]',now())";
mysql_query($sql);
echo"发表成功";
}?>
<form action="add.php" method="post">
用户:<input type="text" name="user" /><br/>
标题:<input type="text" name="title" /><br/>
内容:<textarea name="content"></textarea><br/>
<input type="submit" name="submit" value="发布留言" />
</form>
我看php100视频写的代码,但是我运行后,数据库里面没有添加到纪录,而且页面没有任何提示,也无反应。
我用的是wamp,mysql已经运行了,测试也连接到数据库了,就是不知道为什么提交按钮后,没有反应。
include("conn.php");if($_post['submit']){
$sql="insert into message (id,user,title,content,lastdate) value ('','$_post[user]','$_post[title]','$_post[content]',now())";
mysql_query($sql);
echo"发表成功";
}else{echo "bad";}?>
那么运行add.php页面,也填写表单内容提交后,永远在页面上方显示bad感觉if($_post['submit'])的判断就没有点击提交,不知道为什么?
再回复一次也无妨
1.LZ,请改下判断条件 if($_POST['submit']) 改成 if (isset($_POST['submit']))
2.还有就是把你写的
$sql="insert into message (id,user,title,content lastdate) " .
"values ('','$_POST[user]','$_POST[title]','$_POST[content]','now()')";
这个理的php变量如:$_POST[user]这些变量全都加上大括号
$sql="insert into message (id,user,title,content lastdate) " .
"values ('','{$_POST[user]}','{$_POST[title]}','{$_POST[content]}','now()')";
这行下面做一个echo $sql,然后将页面上显示的sql语句放到phpmyadmin或是其他mysql客户端软件上进行测试你的sql语句是否则正常