数据成功插入Mysql数据库,但未显示任何内容

时间:2019-12-16 00:07:53

标签: mysql database auto-increment

Cust_ID设置为自动递增。最初,从我的网站到数据库的插入不成功,我在网上查看,建议将PK设置为自动增量。我做到了,成功的数据插入消息通过了,但是,在数据库中,没有显示要从网站输入任何数据。我附上了显示两次插入尝试的图片。 Cust_ID的密码分别为1和0,另一个Cust_ID为547。

<?php
    require_once 'Login_Project.php'; // Change this to the file name with your name

    //Create the connection to the MySQL database
    $db_server = mysqli_connect($db_hostname, $db_username, $db_password, $db_database);
    if (!$db_server) die("Unable to connect to MySQL: " . mysqli_error($db_server));

    //$_POST is the ARRAY containing all HTML data that is sent to POST method

    //Store each POST key/value pair in a PHP variable
    foreach($_POST as $key=>$value) ${$key}=$value;

    $id = $_POST['id'];
    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $password = $_POST['password'];
    $username = $_POST['username'];

    //DO something with that value      
    $sql = "INSERT INTO Project_Customers (Cust_ID, Cust_Username, Cust_Password, Cust_FirstName, Cust_LastName, Cust_City) VALUES ('$id', '$username', '$password', '$fname', '$lname', '$city');";

    //As we have already connected to the database, execute the query stored in the $sql variable
    //results of the query get return and stored in the $result variable.
    $result = mysqli_query($db_server, $sql);

    //Check if the query was successfully executed: if the result is NOT FALSE
    if($result) echo "INSERT success!<br />"; else echo "INSERT failed!<br />";

    //More advanced logic can also be done based on success or failure
    if($result)
    {
        //Multiple lines of code should be wrapped in curly braces 
        echo "<p>Data was successfully INSERTED from the database.</p>";
    }
    else
    {
        echo "<p>Your INSERT failed and here's why:</p>";
        die(mysqli_error($db_server));
    }

?>

             CREATE TABLE Customers_Project (Cust_ID int(11) PK AI
             Cust_Username varchar(45) 
             Cust_Password int(11) 
             Cust_FirstName varchar(45) 
             Cust_LastName varchar(45) 
             Cust_City varchar(45);

插入之前

Before Insertion

插入后。插入了新行,但未显示数据

After insertion. A new row was inserted but no data is shown

enter image description here

0 个答案:

没有答案