그냥 빨리 일이, 내가 특정 문자열을 검색하는 것을 시도하고있다 , 그것이 내가이 코드를 실행하면 I 데이터베이스이상한 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
구문에서 실수 한 적이 있습니까? 나는 많은 것을 시도했지만 그것이 될 수있는 것이 단서입니다. -
같은 특수 문자가 포함 된
감사
당신은 당신 때문에 -''의 테이블 이름 주위 역 따옴표가 필요합니다. – Goro
이 때문에 테이블 이름에'-'와 같은 문자를 사용하면 안됩니다. 대신 밑줄을 사용하십시오. – Gogol
또한 while 루프 전에 연결 만들기를 이동해야합니다. (그리고 닫는다.) – Hacketo