I'm having trouble with inserting data into a MySQL
database using PHP
I've looked about around the website looking for similar results but I am not finding exactly what I'm looking for to be able to insert into my table.
I've simplified my code so if it is corrected it can be easily converted for other people to use in the own programs.
My problem is it always seems to fail no matter what way I write the code and fails in the same place it connects to the database and finds the dbname
but can't put data in it.
The error I get from a website:
Error: insert into accounts (Steam ID) VALUES ('YAY') You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ID) VALUES ('YAY')' at line 1
<?php
$serverhost = "localhost";
$pass = "";
$dbname = "website_db";
$table = "";
// Create connection
$connect = mysqli_connect($serverhost, $user, $pass, $dbname);
// Check connection
if (!$connect) {
die("Failed to connect to DataBase: " . mysqli_connect_error());
}
// SQL Variable
$sql = "insert into accounts (Steam ID) VALUES ('YAY')";
// SQL query
if (mysqli_query($connect, $sql)) {
echo "Succesfully Inserted Data to Table";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($connect);
}
// END
mysqli_close($connect);
?>