채택완료

sql 오류 해결 도움 부탁드립니다.

안녕하세요. 

 

php에서 sql 명령어로 테이블에 값을 넣어주는데 오류가 납니다.

 

날짜부분에서 문법이 잘못 되었다고 하는것 같은데 어느부분인지 지적 부탁드립니다.

 

 

1. 코드

Copy
$sql = "insert into `passlog` set
                    `id` = ".$row['mb_id']."
                    ,`name` = ".$row['mb_name']."
                    ,`time` = ".$g4['time_ymdhis']."
                    ,`auth` = ".$authtype."
    ";
    sql_query($sql);

 

2. 에러메세지

insert into `passlog` set `id` = abcde ,`name` = 홍길동 ,`time` = 2019-05-30 14:58:08 ,`auth` =

1064 : 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 '14:58:08 ,`auth` =' at line 4

 

오류 메세지 보면 날짜 시간분초에서 오류나는것 같네요.

 

3. 테이블 구조

 

2039226780_1559196186.1222.jpg

 

감사합니다.

답변 2개 / 댓글 2개

채택된 답변
+20 포인트

문자열 타입의 필드는 값 앞뒤에 '를 붙여주세요.

 

Copy
$sql = "insert into `passlog` set
                   `id` = '".$row['mb_id']."'
                   ,`name` = '".$row['mb_name']."'
                   ,`time` = '".$g4['time_ymdhis']."'
                   ,`auth` = '".$authtype."'
   ";

 

또는

 

Copy
$sql = "insert into `passlog` set
                   `id` = '{$row['mb_id']}'
                   ,`name` = '{$row['mb_name']}'
                   ,`time` = '{$g4['time_ymdhis']}'
                   ,`auth` = '{$authtype}'
   ";

답변에 대한 댓글 1개

감사합니다. 다른 페이지에서는 잘되서 그렇게 했었는데 따옴표가 문제였네요.

,`time` = '".$g4['time_ymdhis']."'

답변에 대한 댓글 1개

감사합니다. 다른필드에서도 오류가나서 보니 모두 따옴표를 추가해줬어야 했네요.

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