后台代码: <?php /** * Created by PhpStorm. * User: jc * Date: 2016/11/21 * Time: 11:35 */ $L_mySql = mysql_connect('localhost','root','root');//函数打开非持久的 MySQL 连接 mysql_select_db('testdb',$L_mySql);//设置活动的 MySQL 数据库 mysql_query('set name utf8',$L_mySql);//设置查询出来的数据为utf8字符集 if (!empty($_REQUEST["t"]))//判断提交的用户名是否为空 { $L_text = $_REQUEST["t"]; } $sql = "insert into comment(text)value ('$L_text')"; $L_return = mysql_query($sql, $L_mySql) or exit(mysql_error());//执行mysql查询 $L_row=mysql_affected_rows($L_mySql); if ($L_row>0) { echo "<script type=text/javascript>alert('回复成功');window.location.href='comment.php';</script>"; }