Home > Backend Development > PHP Tutorial > 写了一个简单留言板发布代码,但总是无法把留言录入MySQL数据库中,求大神指点异常

写了一个简单留言板发布代码,但总是无法把留言录入MySQL数据库中,求大神指点异常

WBOY
Release: 2016-06-13 11:37:42
Original
758 people have browsed it

写了一个简单留言板发布代码,但总是无法把留言录入MySQL数据库中,求大神指点错误!
    我初学php和mysql,模仿php100视频教程做一个留言板发布网站,但点击“留言“按钮后总是弹出“留言失败!”,同时数据库中也没有导入信息,求大神看一下哪出代码出问题了,谢谢!
     数据库 名称:test_liuyanban
     表 名称:message
     字段:int(主键)、username(用户名)、email(邮箱)、content(留言内容)。
     一共两个文件:conn.php和index.php
     conn.php:
$conn = @mysql_connect('localhost','root','12345')or die('连接失败!');
@mysql_select_db("test_liuyanban")or die('没有该数据库!');
mysql_query("set names 'GBK'");
?>
     
     index.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>alert('留言成功!');location.href='index.php'</script>";
    }else{
        echo"<script>alert('留言失败!');location.href='index.php'</script>";
    }
}
?>




    


        
        
            
            
        
        
            
            
        
        
            
            
        
        
        
        
    



用户名:
E-mail:
留言内容:

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template