做了最新实验,我的代码发给朋友,没有改动,数据库可以正常添加代码,但是我这边就不行,是数据库问题么?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link href="css.css" rel="stylesheet" type="text/css">
<title>Title</title>
<?php include ("add.php")?>
</head><body>
<hr size=1>
<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
header("Content-type: text/html; charset=utf-8");
include ("conn.php");
$id=$_POST['id'];
$user=$_POST['user'];
$title=$_POST['title'];
$content=$_POST['content'];
if ($_POST['submit']){
$sql="insert into message(id,user,title,content,lastdate)values('','$user','$title','$content',now())";
mysql_query($sql);
echo "<script>alert('提交成功!返回首页。');location.href='add.html';</script>";
}
?>
数据库一点变化没有
其他代码也放一下
<?php
$conn =mysql_connect("localhost", "root", "root") or die("数据库链接错误");
mysql_select_db("test", $conn);
mysql_query("set names 'utf8'"); //使用utf-8中文编码;
?>
<!DOCTYPE html>
<html lang="utf-8">
<Meta http-equiv="Content-Type" Content="text/html; Charset=utf-8">
<head>
<?php
include ("conn.php");
?>
<link href="css.css" rel="stylesheet" type="text/css">
</head>
<table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef" >
<?php
$sql="select * from message order by id desc";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query)){ ?>
<tr bgcolor="#eff3ff">
<td>标题: <?php echo $row['title'];?> <font color="red">用户: <?php echo $row['user'];?> </td>
</tr>
<tr bgColor="#ffffff">
<td>发表内容:<?php echo $row['content'];?></td>
</tr>
<tr bgColor="#ffffff">
<td><div align="right">时间:<?php echo $row['lastdate'];?></td>
</tr>
<?php } ?>
<tr bgcolor="#f0fff0">
<td><div align="right"><a href="add.html">返回留言</a> </td>
</tr>
</table>
</html>