问题
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