이전 목록 다음
채택완료

Mysql문의

2022-08-18 (목) 16:14:53 2,165
Copy
<?php
include_once "**********";

$how = $_GET['how'];
$times = time();
$Bids = $_GET['Bids'];
$Sno = $_GET['Sno'];
$memoSno = $_GET['memoSno'];
$contents = $_GET['contents'];

print_r($_GET);

if($how == "reple"){
    $A = "INSERT INTO `alertmemo` (`memoSno`,`times`,`bid`,`sno`,`contents`) 
    VALUES (`".$memoSno."`,`".$times."`,`".$Bids."`,`".$Sno."`,`".$contents."`)";
    mysqli_query($conn,$A)or die(mysqli_error());
} // 답글에 댓글
else if($how == "edit"){
    
    
} // 수정
else if($how == "delete"){
    $A = "DELETE FROM alertmemo WHERE memoSno=`".$memoSno."`";
    mysqli_query($conn,$A);
    
    
} // 삭제
else if($how == "write"){
    $A = "INSERT INTO alertmemo ('contents','times','bid','sno','memoSno') VALUES ('".$contents."','".$times."','".$Bids."','".$Sno."','".$memoSno."')";
    
    mysqli_query($conn,$A);
    
    print mysqli_error($conn);
    
}  //댓글 작성

?>

위소스를 돌리면 아래 오류가 뿜어져 나오는데요 어디가 잘못 되 었 을 까요?

Copy
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 ''contents','times','bid','sno','memoSno') VALUES ('test','1660806739','TNBreview' at line 1
|

답변 2개 / 댓글 1개

채택된 답변
+20 포인트
2022-08-18 (목) 16:24:44
Copy
// $A = "INSERT INTO alertmemo ('contents','times','bid','sno','memoSno') VALUES ('".$contents."','".$times."','".$Bids."','".$Sno."','".$memoSno."')";


 $A = "INSERT INTO alertmemo (`contents`,`times`,`bid`,`sno`,`memoSno`) VALUES ('".$contents."','".$times."','".$Bids."','".$Sno."','".$memoSno."')";

백틱으로 바꿔보세요

답변에 대한 댓글 1개

질문자님께,
컬럼 이름에 꼭 필요한 경우를 빼고는
따옴표를 쓰실 필요는 없습니다.
2022-08-18 (목) 16:24:44

쿼리에 홑따옴표 쌍따옴표 같이 쓸필요가 없을텐데요..

그냥

$A = "INSERT INTO alertmemo ('contents','times','bid','sno','memoSno') VALUES ('$contents','$times','$Bids','$Sno','$memoSno')";

답변을 작성하려면 로그인이 필요합니다.