I'm trying to insert some data into a DB on my local machine.
I've opened up the connection, and performed the INSERT INTO for the fields I require. Nothing is showing up in the database but I'm really lost as I'm not getting any errors either, so no guidance as to where it is failing. I have tried scaling it back and adding in echo variables to check how far the script is running but it runs all the way to the end.
To start I set the password and username which is just my local stuff:
// configuration
$dbuser = "root";
$dbpass = "";
Then I create the connection
// Create connection
$con=mysqli_connect("localhost",$dbuser,$dbpass,"survey");
Because I was struggling to find out where it was falling over, I have included an error statement. At present it outputs 'successfully connected'
so it's not failing to connect...
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}else{
echo 'successfully connected';
}
And then I'm preparing the SQL INSERT INTO
// the SQL insert
mysqli_query($con,"INSERT INTO mytablename (MostImportantFeatures,ImportanceOfFreeDelivery)
VALUES ($features,$importance_free_delivery)");
mysqli_close($con);
And I am getting nothing back. No errors, but no submission to the database. I cannot work out where I've gone wrong or how I can debug this as the script runs through. I can log into the database (using Sequel Pro) with the details above just fine.
How would you start to debug this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…