이전 사이트에서 작동했지만 더 이상 작동하지 않는 다음 코드가 있습니다. 값을 입력하고 이중 이름을 확인해야하는 값으로 변경했습니다.Mysql 오류 - SQL 구문에 오류가 있습니다.
<?php
/*
Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password)
*/
$link = mysqli_connect("localhost", "***", "***", "***");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Escape user inputs for security
$cname = mysqli_real_escape_string($link, $_POST['cname']);
$name = mysqli_real_escape_string($link, $_POST['name']);
$contact = mysqli_real_escape_string($link, $_POST['contact']);
$reason = mysqli_real_escape_string($link, $_POST['reason']);
// attempt insert query execution
$sql = "INSERT INTO keys (cname, name, contact, reason) VALUES ('$cname', '$name', '$contact', '$reason')";
if(mysqli_query($link, $sql)){
echo "<script>alert('User added!')</script>";
echo "<script>window.open('index.php','_self')</script>";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// close connection
mysqli_close($link);
?>
내가 할 모든 양식을 제출 다음과 같은 오류입니다 :
MySQL의 오류가 - 당신은 당신의 SQL 구문 내가 잘못 뭐하는 거지
에서 오류가?
'keys'는 예약 된 mysql 단어입니다. –
@ GurwinderSingh 잘못된 구문입니다. MySQL은 대괄호가 아닌 백틱을 사용합니다. https://dev.mysql.com/doc/refman/5.5/en/identifiers.html을 참조하십시오. –