<!--DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加留言</title>
</head>
<body-->
<?php
include("conn.php");
if('$_POST[submit]'){
$sql="INSERT INTO message (user,title,content,lastdate) VALUES ('$_POST[user]','$_POST[title]','$_POST[content]',now())";
mysql_query($sql);
echo("成功!");
}
?>
<form action="add.php" method="post">
用户:
<input type="text" size="10" name="user" />
<br />
标题:
<input type="text" name="title" />
<br />
内容:
<textarea name="content"></textarea>
<br />
<input type="submit" value="发布留言" />
</form><!--/body>
</html-->
为什么把HTML代码注释起来才可以添加到MySQL数据库里,注释起来之后页面显示乱码。
如果不注释的话添加不到数据库里。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加留言</title>
</head>
<body-->
<?php
include("conn.php");
if('$_POST[submit]'){
$sql="INSERT INTO message (user,title,content,lastdate) VALUES ('$_POST[user]','$_POST[title]','$_POST[content]',now())";
mysql_query($sql);
echo("成功!");
}
?>
<form action="add.php" method="post">
用户:
<input type="text" size="10" name="user" />
<br />
标题:
<input type="text" name="title" />
<br />
内容:
<textarea name="content"></textarea>
<br />
<input type="submit" value="发布留言" />
</form><!--/body>
</html-->
为什么把HTML代码注释起来才可以添加到MySQL数据库里,注释起来之后页面显示乱码。
如果不注释的话添加不到数据库里。
解决方案 »
- PHP重点基础知识整理[长期更新]
- 还是关于上传到空间的问题,我安装了PHP,APACHE,MYSQL,在APACHE的HTDOC文件夹下写的PHP文件都能正常执行,那么我怎么把这些文件传到空间上去呢?
- utf-8 截取中文
- 关于自动生成链接的问题
- echo $avg = round($result[0],2);怎么实现大于0才显示?
- 关于mysql查询url的问题
- pcntl_fork这个函数如何监控子进程?
- 聊天室怪问题!!!我受不了了!!
- 巨难问题:PHP 的crypt()函数怎么用?出错16次了。。。
- php问题,请好心的朋友来帮我一下,万分感谢
- php 文件第一次加载404,刷新就可以了??
- 哪位高人给介绍一下fsockopen的应用?
include("conn.php");
if($_SERVER["REQUEST_METHOD"] == "POST"){
$sql="INSERT INTO message (user,title,content,lastdate) VALUES ('$_POST[user]','$_POST[title]','$_POST[content]',now())";
mysql_query($sql);
echo("成功!");
}
?>
把HTML头和尾注释掉之后就可以添加到数据库里了,但页面就成乱码了!
打印insert语句,还有显示mysql_error()信息
“鎴愬姛!
鐢ㄦ埛锛�
鏍囬锛�
鍐呭锛”�
这样的乱码。如何才能使页面运行和显示显示正常。
出现的问题是:运行正常显示不正常,显示正常运行不正常!
显示正常的时候运行还不报错,就是不会把表单数据提交到数据库!
include("conn.php");
if($_POST["submit"]){
$sql="INSERT INTO message (user,title,content,lastdate) VALUES ('$_POST[user]','$_POST[title]','$_POST[content]',now())";
mysql_query($sql);
echo("成功!");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加留言</title>
</head>
<body>
<form action="add.php" method="post">
用户:
<input type="text" size="10" name="user" />
<br />
标题:
<input type="text" name="title" />
<br />
内容:
<textarea name="content"></textarea>
<br />
<input type="submit" name="submit" value="发布留言" />
</form></body>
</html>
<?php....?>应该放到最前面位置。否则_Post这类值是无法被正确取得的。<?php
include("conn.php");
if('$_POST[submit]'){
$sql="INSERT INTO message (user,title,content,lastdate) VALUES ('$_POST[user]','$_POST[title]','$_POST[content]',now())";
mysql_query($sql);
$flag = true;
//echo("成功!");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加留言</title>
</head>
<body><form action="add.php" method="post">
用户:
<input type="text" size="10" name="user" />
<br />
标题:
<input type="text" name="title" />
<br />
内容:
<textarea name="content"></textarea>
<br />
<input type="submit" value="发布留言" />
<? if($flag) echo "成功";?>
</form></body>
</html>
他自己不显示,你就让他输出啊,echo。。要不你把你代码拆开来,第一页放form那段,第二页放数据库操作,操作完再location.href(url)回到第一页。