日期:2014-05-17  浏览次数:20480 次

写了一个简单留言板发布代码,但总是无法把留言录入MySQL数据库中,求大神指点错误!
    我初学php和mysql,模仿php100视频教程做一个留言板发布网站,但点击“留言“按钮后总是弹出“留言失败!”,同时数据库中也没有导入信息,求大神看一下哪出代码出问题了,谢谢!
     数据库 名称:test_liuyanban
     表 名称:message
     字段:int(主键)、username(用户名)、email(邮箱)、content(留言内容)。
     一共两个文件:conn.php和index.php
     conn.php:
<?php
$conn = @mysql_connect('localhost','root','12345')or die('连接失败!');
@mysql_select_db("test_liuyanban")or die('没有该数据库!');
mysql_query("set names 'GBK'");
?>
     
     index.php:
<?php
include_once'conn.php';
if($_POST['post']){
    $sql="insert into `message` (id,username,email,content) values ('','$_POST[username]','$_POST[email]','$_POST[content]')";
    $result=mysql_query($sql);
    if($result){
        echo"<script type='text/javascript'>alert('留言成功!');location.href='index.php'</script>";
    }else{
        echo"<script type='text/javascript'>alert('留言失败!');location.href='index.php'</script>";
    }
}
?>
<html>
<head>
</head>
<body>
    <form action="" method="post">
        <table border="0" width="500">
        <tr>
            <td width='100' align='right'>用户名:</td>
            <td><input type='text' name='username' value=''/></td>
        </tr>
        <tr>
            <td width='100' align='right'>E-mail:</td>
            <td><input name="email" type="text" value=""></td>
        </tr>
        <tr>
            <td width='100' align='right'>留言内容:</td>
            <td><textarea name='content'></textarea></td>
        </tr>
        <tr>
        <td colspan='2' align='center'><input type='submit' name='post' value='留言'/></td>
        </tr>
    </form>
</body>
</html>