PHP failed to connect to database
phpcn_u39497
phpcn_u39497 2017-10-07 13:26:36
0
2
1151

<?php

header("content-type:text/html;charset=gb2312");

$conn=mysqli_connect("locallost","root","root","study");

mysqli_set_charset($conn,"utf-8");

if($conn){

    switch($_GET["action"]){

       case 'add';

           $name=$_POST['name'];

           $sex=$_POST['sex'];

           $age=$_POST['age'];

           $class=$_POST['class'];

           $sql="insert into stu(name,sex,age,class)values('$name','$sex','$age','$class')";

           $rw=mysqli_query($conn,$sql);

             if($rw>0){

                 echo "<script>alert('add success添加成功');</script>";

             }else{

                 echo "<script>alert('add failure添加失败');</script>";

             }

             header(‘Location:index.php’);

             break;

       }

}

?>


phpcn_u39497
phpcn_u39497

reply all(2)
虫儿飞

What error is reported~

散步咏凉天

Pay more attention to whether the conditions during link configuration are written incorrectly. For example, password, user name, etc., and check the code for errors

  • reply The code is correct. I wrote it in Notepad. Is there any problem related to this?
    phpcn_u39497 author 2017-10-07 16:07:13
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template