Просто быстро вещь, Я пытаюсь искать для конкретной строки, все это находит мне нужно вставить в базу данныхСтранно MySQL ошибка синтаксиса вставки
Когда я запускаю этот код:
<?php
$search = 'permanently';
$logfile = 'ban_list.txt';
// Read from file
$file = fopen($logfile, "r");
while(($line = fgets($file))!= false)
{
if(stristr($line,$search)) // case insensitive
echo "<font face='Arial'> $line </font><hr>";
?>
<?php
$servername = "localhost";
$username = "root";
$password = "pass";
$dbname = "db";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO ingame-banlist (Ban, Timestamp) VALUES ('$line', '$timestamp')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
fclose($file);
?>
я получаю эту ошибку:
118441 # reichskommisar is banned permanently by A_GismoDyret.
Error: INSERT INTO ingame-banlist (Ban, Timestamp) VALUES ('', '0')
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-banlist (Ban, Timestamp) VALUES ('', '0')' at line 1 1213174 # SwagFurMeinFuhrer is banned permanently by HA_Vincent.
Error: INSERT INTO ingame-banlist (Ban, Timestamp) VALUES ('', '0')
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-banlist (Ban, Timestamp) VALUES ('', '0')' at line 1 1394124 # Kick_Ass is banned permanently by HA_Vincent.
Error: INSERT INTO ingame-banlist (Ban, Timestamp) VALUES ('', '0')
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-banlist (Ban, Timestamp) VALUES ('', '0')' at line 1 Error: INSERT INTO ingame-banlist (Ban, Timestamp) VALUES ('', '0')
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-banlist (Ban, Timestamp) VALUES ('', '0')' at line 1 Error: INSERT INTO ingame-banlist (Ban, Timestamp) VALUES ('', '0')
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-banlist (Ban, Timestamp) VALUES ('', '0')' at line 1 Error: INSERT INTO ingame-banlist (Ban, Timestamp) VALUES ('', '0')
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-banlist (Ban, Timestamp) VALUES ('', '0')' at line 1 Error: INSERT INTO ingame-banlist (Ban, Timestamp) VALUES ('', '0')
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-banlist (Ban, Timestamp) VALUES ('', '0')' at line 1 Error: INSERT INTO ingame-banlist (Ban, Timestamp) VALUES ('', '0')
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-banlist (Ban, Timestamp) VALUES ('', '0')' at line 1 1762050 # VladimirKozlov is banned permanently by SO_Conner. # do not unban
ли я сделать misstake в моем синтаксисе? Я много пробовал, но я не знаю, что это может быть.
Благодаря
Вы должны вас кавычка вокруг имени таблицы из-за '-'. – Goro
Вот почему вы никогда не должны использовать такие символы, как '-' в именах таблиц. Вместо этого используйте подчеркивание. – Gogol
Также вы должны переместить создание соединения до цикла while. (и закройте его после) – Hacketo