There are similar questions about this but none of the solutions help me. Is there anyone who can tell the problem here?
This is my code
<?php
// Create connection
$conn = new mysqli("localhost", "root", "", "mydb");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
for ($i=0; $i < 10; $i++) {
$dec = $i;
$hex = dechex($dec);
$sql = "
INSERT INTO mytable (dec, hex)
VALUES ('$dec', '$hex')
";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
$conn->close();
?>
And this is the error I get:
Error: INSERT INTO mytable (dec, hex) VALUES (0, 0)
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 'dec, hex) VALUES (0, 0)' at line 1Error: INSERT INTO mytable (dec, hex) VALUES (1, 1)