I have the following code in a PHP file to process the data from a form the user fills out. They input numeric score predictions for football matches, and I take them and add them to a database so they can be displayed on a later page on the website.
$servername = "127.0.0.1";
$username = "root";
$password = NULL;
$dbname = "worldCup";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("There's been a glitch in the matrix: " . $conn->connect_error);
}
$sql = "INSERT INTO teamResults (Awinner, Arunner, Bwinner, Brunner, Cwinner, Crunner, Dwinner, Drunner) VALUES ($Awinner, $Arunner, $Bwinner, $Brunner, $Cwinner, $Crunner, $Dwinner, $Drunner)";
if ($conn->query($sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
When I do this, I get an error saying that "Unknown column "Russia" in field list". "Russia" is the content of the first variable, Awinner. Anybody know what's going on here?
NOTE: When reading from the database on other webpages, it works fine, and reads the default placeholder data I manually put into the database through MySQL. AFAIK it is not an issue with connecting to the actual MySQL database. Could there be something in the actual settings of the MySQL database that I need to activate in order to edit from PHP?