2012-11-25 3 views
2

글쎄,이 새로운 PHP PDO를 사용하기 시작했고,이 문제가 발생했습니다. 데이터베이스가 19 개가 넘는 테이블로 구성되어 있습니다. 일부는 자동으로 데이터베이스에 의해 자체적으로 처리되기 때문에 코드의 삽입 섹션에 공백이 있습니다.PHP PDO를 MySQL에 삽입 오류 SQL 구문

프로세스가 전화 번호를 데이터베이스에 입력하려고하면 오류가 발생합니다. 데이터베이스가 12 varchar를 수락하도록 설정됩니다. 수뿐만 아니라 12 VARCHAR를 가지고,하지만 난 디버깅 정보를 볼 때, 그것은 전체 기능은 전화 번호의 마지막 자리를 ommiting 내게의 오류주고있다 같습니다

array (
    0 => '42000', 
    1 => 1064, 
    2 => '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 \') 

을 나는 확실하지 않다 여기에 무슨 일이 일어나고 있는지. 누군가가 올바른 방향으로 나를 가리킬 수 있다면 그것은 좋을 것입니다. 다음은 스크립트 코드입니다.

<?php 
require_once('../wp-includes/class-phpass.php'); 

//Create var names 
$first_name = $_POST['F_Name']; 
$last_name = $_POST['L_Name']; 
$phone_number_1 = $_POST['Pnumber1']; 
$phone_number_2 = $_POST['Pnumber2']; 
$address = $_POST['Address']; 
$state = $_POST['State']; 
$city = $_POST['City']; 
$zip_code = $_POST['Zip']; 
$email_1 = $_POST['Email1']; 
$email_2 = $_POST['Email2']; 
$username = $_POST['Uname']; 
$password_1 = $_POST['Pass']; 
$jed = $_POST['Jednostka']; 
$dob = $_POST['DOB']; 
$stopien = $_POST['Stopien']; 
$funk = $_POST['FUNK']; 
$fullName = $_POST['F_name'].' '.$_POST['L_name']; 
$hasher = new PasswordHash(8, True); 
$password = $hasher->HashPassword($password_1); 
$ENC =MD5($password_1); 
$ERRmsg = ""; 

    //Checks if any feilds were left empty and creates an error message to display 
     if(empty($first_name)) $ERRmsg .= 'You did not enter a First Name! Pleaase go back and try again! <br/>'; 
     if(empty($last_name)) $ERRmsg .= 'You did not enter a Last Name! Please go back and try again! <br/>'; 
     if(empty($phone_number_1)) $ERRmsg .= 'You did not enter a Phone Number! Please go back and try again! <br/>'; 
     if(empty($address)) $ERRmsg .= 'You did not enter an Address! Please go back and try again! <br/>'; 
     if(empty($state)) $ERRmsg .= 'You did not choose a State! Please go back and try again! <br/>'; 
     if(empty($city)) $ERRmsg .= 'You did not enter a City! Please go back and try again! <br/>'; 
     if(empty($zip_code)) $ERRmsg .= 'You did not enter a Zip Code. Please go back and try again!<br/>'; 
     if(empty($email_1)) $ERRmsg .= 'You did not enter a Email. Please go back and try again!<br/>'; 
     if(empty($email_2)) $ERRmsg .= 'You did not re-enter you Email. Please go back and try again!<br/>'; 
     if(empty($username)) $ERRmsg .= 'You did not enter a Username. Please go back and try again!<br/>'; 
     if(empty($password_1)) $ERRmsg .= 'You did not enter a password! Please go back and try again!<br/>'; 
     if(empty($jed)) $ERRmsg .= 'You did not choose a Jednostka! Please go back and try again!<br/>'; 
     if(empty($dob)) $ERRmsg .= 'You did not enter a Date of Birth! Please go back and try again!<br/>'; 
     if(empty($stopien)) $ERRmsg .= 'You did not choose a Stopien! Please go back and try again!<br/>'; 
     if(empty($funk)) $ERRmsg .= 'You did not enter a Funkcjia! Please go back and try again!<br/>'; 
     if($email_1 !== $email_2) $ERRmsg .= 'Your emails did not match! Please go back and try again!<br/>'; 

      //Checks to see if error message is empty, if empty does rest of code 
      if(empty($ERRmsg)) 
      { 
       try { 
       $wdp = new PDO('mysql:host=localhost; dbname=***********', '***********', '***********'); 
        echo "<p>Connected to Warta Database</p>\n"; 
       $wdp->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
         //prepare the SQL statement 
          $wdp_insert = $wdp->prepare 
          ("INSERT INTO Users( 
          F_NAME, 
          L_Name, 
          P_number1, 
          P_number2, 
          Address, 
          City, 
          State, 
          Zip, 
          Email, 
          username, 
          password, 
          Jednostka, 
          DOB, 
          Stopien, 
          Funkcjia, 
          High, 
          Active, 
          user_email, 
          user_login, 
          user_pass, 
          user_nicename, 
          display_name, 
         ) 
         VALUES (
          :fname, 
          :lname, 
          :pnumber1, 
          :pnumber2, 
          :address, 
          :city, 
          :state, 
          :zip, 
          :email, 
          :username, 
          :password, 
          :jednostka, 
          :DOB, 
          :Stopien, 
          :funkcjia, 
          :jednostka, 
          0, 
          :email, 
          :username, 
          :password, 
          :fullname, 
          :fullname, 
         )" 
         ); 

           //Bind the paramaters 
           $wdp_insert->bindParam(':fname', $first_name); 
           $wdp_insert->bindParam(':lname', $last_name); 
           $wdp_insert->bindParam(':pnumber1', $phone_number_1); 
           $wdp_insert->bindParam(':pnumber2', $phone_number_2); 
           $wdp_insert->bindParam(':address', $address); 
           $wdp_insert->bindParam(':city', $city); 
           $wdp_insert->bindParam(':state', $state); 
           $wdp_insert->bindParam(':zip', $zip_code); 
           $wdp_insert->bindParam(':email', $email_1); 
           $wdp_insert->bindParam(':username', $username); 
           $wdp_insert->bindParam(':password', $password); 
           $wdp_insert->bindParam(':jednostka', $jed); 
           $wdp_insert->bindParam(':DOB', $dob); 
           $wdp_insert->bindParam(':Stopien', $stopien); 
           $wdp_insert->bindParam(':funkcjia', $funk); 
           $wdp_insert->bindParam(':fullname', $fullName); 

         //Execute the prepared statement 
          $wdp_insert->execute(); 
          echo ("<p>Insert complete</p>\n"); 
       } catch (PDOException $ex) { 
       $msg = $ex->errorInfo; 
       error_log(var_export($msg, true)); 
       die("<p>Sorry, there was an unrecoverable database error. Debug data has been logged.</p>"); 
       }; 

      } 
      else { 
       echo ($first_name .' '. $ERRmsg); 
       exit; 
      } 

?> 

도움이 될 것입니다.

답변

1

displayname:fullname 다음에 끝 괄호 앞에 쉼표가 없어야합니다.

. . . 
user_nicename, 
display_name,  <-- superfluous comma 
) 
VALUES (
. . . 
:fullname, 
:fullname,  <-- superfluous comma 
)" 

일부 언어 (예 : PHP 및 Perl)는 목록의 마지막 요소 다음에 쉼표를 허용하지만 SQL은 허용하지 않습니다.

3

그것의 당신의 SQL

제거 display_name, & :fullname,

의 마지막 ,