数据未插入表,数据库连接无错误

我对 PHP 很陌生,一个学生刚刚创建了我的第一个登录系统。数据库连接成功但表中没有插入数据


我已经回显了它从注册表单中获取值的变量。


<?php

$conn = "mysqli_connect('localhost','root','','user')";

if ($conn) {

    $username = $_POST['username'];

    $password = $_POST['password'];

    $conf_password = $_POST['conf_password'];


    if ($username == '' || $password == '' || $conf_password == '') {

        echo "Incomplete credentials ";

        exit;

    } else {

        if ($password == $conf_password) {

            $query = "INSERT INTO table1(Sno,Username,Password)

              VALUES(NUll,'$username','$password')";


            $exec_query = "mysqli_query($conn,$query)";

            if ($exec_query) {

                echo "User Inserted";

                echo $username;

                echo $password;

                echo $conf_password;

            } else {

                echo "Error Occurred";

            }

        } else {

            echo "Please confirm Password";

        }

    }

}


"mysqli_close($conn)";

?>`

预期 - 数据插入 table1


慕雪6442864
浏览 137回答 2
2回答

翻过高山走不出你

mysqli_query是一个函数删除引号将其写为&nbsp;mysqli_query($conn,$query)和相同的mysqli_close($conn)

蛊毒传说

你能试试这个吗?<?php&nbsp; &nbsp; $conn = mysqli_connect('localhost','root','','user');&nbsp; &nbsp; if($conn)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; $username=$_POST['username'];&nbsp; &nbsp; &nbsp; &nbsp; $password=$_POST['password'];&nbsp; &nbsp; &nbsp; &nbsp; $conf_password=$_POST['conf_password'];&nbsp; &nbsp; &nbsp; &nbsp; if ($username==''||$password==''||$conf_password=='')&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "Incomplete credentials ";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; else&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($password == $conf_password)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $query= "INSERT INTO table1(Sno,Username,Password)&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VALUES(NULL,'$username','$password')";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $exec_query= mysqli_query($conn,$query);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ($exec_query)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "User Inserted";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo $username;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo $password;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo $conf_password;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "Error Occurred";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "Please confirm Password";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; mysqli_close($conn);&nbsp; &nbsp;?>Expecting - Data inserted into table1
打开App,查看更多内容
随时随地看视频慕课网APP