以下是我的代码:
<?php
$conn = mysql_connect("localhost", "root", "panpan") or die("数据库链接错误");
mysql_select_db("bba", $conn);
mysql_query("set names utf-8"); //使用GBK中文编码;if($_POST['submit']){
$sql="insert into massge(user,title) " .
"values('$_POST[user]','$_POST[title]')";
$query=mysql_query($sql);
if($query){
echo "发表不能成功";
}else {
echo "插入失败";
}
}
mysql_close($conn);
?>
<!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 id="form1" name="form1" method="post" action="add.php">
<p>
<label>用户:
<input type="text" name="user" id="user" />
</label>
</p>
<p>
<label>标题:
<input type="text" name="title" id="title" />
</label>
</p>
<p>
<label>
<input type="submit" name="submit" id="submit" value="提交" />
</label>
</p>
</form>
</body>
</html>
<?php
$conn = mysql_connect("localhost", "root", "panpan") or die("数据库链接错误");
mysql_select_db("bba", $conn);
mysql_query("set names utf-8"); //使用GBK中文编码;if($_POST['submit']){
$sql="insert into massge(user,title) " .
"values('$_POST[user]','$_POST[title]')";
$query=mysql_query($sql);
if($query){
echo "发表不能成功";
}else {
echo "插入失败";
}
}
mysql_close($conn);
?>
<!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 id="form1" name="form1" method="post" action="add.php">
<p>
<label>用户:
<input type="text" name="user" id="user" />
</label>
</p>
<p>
<label>标题:
<input type="text" name="title" id="title" />
</label>
</p>
<p>
<label>
<input type="submit" name="submit" id="submit" value="提交" />
</label>
</p>
</form>
</body>
</html>
还可以把 mysql_error输出来看看
"values('$_POST[user]','$_POST[title]')";
$query=mysql_query($sql);
这句中得标红部分是不是该这么写:
$sql="insert into massage(user,title) " .
"values('$_POST[user]','$_POST[title]')";
$query=mysql_query($sql);