Insertion of data into Mysql database is successful, but nothing shows up

风流意气都作罢 提交于 2019-12-25 17:06:43

问题


Cust_ID is set to auto-increment. Initially, the insertion was not successful from my website to the database and I looked online and a suggestion was to set the PK to auto-increment. I did that and the successful data insertion message came through, however, in the database, no data was shown to be entered from the website. I attached pictures that show two attempts of insertion. The Cust_ID came back as 1 and 0 for the password and 547 for another Cust_ID.

<?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

来源:https://stackoverflow.com/questions/59349186/insertion-of-data-into-mysql-database-is-successful-but-nothing-shows-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!