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

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

QA

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

답변 2

본문

안녕하세요. 

 

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

 

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

 

 

1. 코드


    $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

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

 

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

 

또는

 

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

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

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 0
© SIRSOFT
현재 페이지 제일 처음으로