Home > Backend Development > PHP Tutorial > PHP链接MySQL问题。新手求助

PHP链接MySQL问题。新手求助

WBOY
Release: 2016-06-23 13:58:08
Original
915 people have browsed it



    
    


if(@$_POST["submit"]){
    $id = $_POST["id"];
    $name = $_POST["name"];
    $age = $_POST["age"];
    $tel = $_POST["tel"];
    $address = $_POST["address"];



    $conn = @mysql_connect("localhost","root","ROOT") or die("数据库连接超时,请稍后再试!");
    mysql_select_db("test",$conn);
    mysql_query("set names 'utf8'");

    $sql = "select * from `student`";
    $sql = "INSERT INTO `student`(`id`, `name`, `age`, `tel`, `address`) VALUES ('$id','$name','$age','$tel','$address')";
    mysql_query($sql);
}
?>



    编  号:  

    姓  名:  

    年  龄:  

    电  话:  

    地  址:  

    
















这是我建的数据表、  进入页面添加数据生成再刷新数据表内容是空的。是什么问题呢?


回复讨论(解决方案)

编码问题 插入的文字编码和数据库的编码不一致

能说具体一点吗。该怎样修改。谢谢

mysql_query($sql) or die(mysql_error())看下错误是什么?

 没有报错...                 谢谢帮助了

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