2013-06-12 2 views
-1

나는이 코드를 흘려서 오류의 원인이 될 수있는 것을 찾을 수 없습니다. 어떤 제안?INSERT시 MySQL 오류 코드 1064 받기

$sql = "INSERT INTO users (`id`, `username`, `password`, `firstname`, 
     `lastname`, `photo`, `mobile`, `fax`, `bday`, `homeadd`, `city`, 
     `state`, `zip`, `mailingadd`, `altfax`, `altphone`, `email`, 
     `emailpass`, `website`, `bio`, `designations`, `photo2`, `type`, 
     `confirmed_email`, `registered_on`, `disabled`, `admin_disabled`) 
     VALUES (NULL, $username, MD5('$password'), $firstname, $lastname, 
     '', 'test', '', '', '', '', '', '', '', '', '', $email, '', '', '', '', 
     '', 'agent', '1', NOW(), $disabled, 0)";` 
+2

전체 오류 메시지를 보내주십시오. –

답변

0

변수는 여전히 작은 따옴표로 묶어야합니다. '$variable'을 삽입 할 때마다 작은 따옴표를 그 주위에 던져 넣으십시오.

0
당신은 당신의 개별 값 따옴표를 추가해야

: 그들은 '이후

$sql  = "INSERT INTO users 
(`id`, `username`, `password`, `firstname`, `lastname`, `photo`, `mobile`, `fax`, `bday`, `homeadd`, `city`, `state`, `zip`, `mailingadd`, `altfax`, `altphone`, `email`, `emailpass`, `website`, `bio`, `designations`, `photo2`, `type`, `confirmed_email`, `registered_on`, `disabled`, `admin_disabled`) VALUES 
(NULL, '$username', MD5('$password'), '$firstname', '$lastname', '', 'test', '', '', '', '', '', '', '', '', '', '$email', '', '', '', '', '', 'agent', '1', NOW(), '$disabled', 0)"; 

정말 * mysql_로 떨어져 점점 기능을 권하고 싶습니다 : 당신은 변수를 인용하지 않을

$sql = "INSERT INTO users (id,username,password,firstname,lastname,photo,mobile,fax,bday,homeadd,city,state,zip,mailingadd,altfax,altphone,email,emailpass,website,bio,designations,photo2,type,confirmed_email,registered_on,disabled,admin_disabled) VALUES (NULL, '$username', MD5('$password'), '$firstname', '$lastname', '', 'test', '', '', '', '', '', '', '', '', '', '$email', '', '', '', '', '', 'agent', '1', NOW(), $disabled, 0)"; 
+0

이제 열 개수가 행 개수와 일치하지 않는다고 말하는 것입니다 ... 분명히 ... –

+0

이 대답을 붙여 넣으시겠습니까? 이 대답은 틀린 문법입니다. ''$ disabled ''주위에 작은 따옴표가 필요합니다. –

+0

비활성화 된 값이 부울 또는 INT 일 경우 따옴표는 $ 필요하지 않지만 내용이 불확실한 경우 권장되는 것에 동의합니다. 또한 Stanislav의 답변을 권합니다. 작은 따옴표가 속성 이스케이프 처리되어 계속되는 문제의 원인이 될 수 있으므로이 답변을 권합니다. –

0

향후 버전에서는 더 이상 사용되지 않으며 작동하지 않을 예정입니다. PDO 또는 MySQLi를 사용하는 경우 바인딩 함수를 사용할 수 있으므로 값을 따옴표로 묶을 필요가 없습니다.

1

모든 문자열 값에 이스케이프를 추가하십시오. 다음은 PHP 함수입니다 : mysqli_real_escape_string(). 그리고 코드를 사용하여 리팩터링해야합니다. PDO