2013-05-16 2 views
0

대부분 여러 테이블을 사용하여 보았습니다. 한 두 번씩 나는 5 개의 테이블을 구체적으로 검색했다. 예제는 주로 두 개의 테이블 만 표시합니다.5 개의 테이블에 대한 mysql 업데이트

아래 코드를 실행하면 다음 메시지가 나타납니다. memret 업데이트 1 : SQL 구문에 오류가 있습니다. 근처에있는 올바른 구문을 보려면 MySQL 서버 버전에 해당하는 설명서를 확인하십시오. '(M.first = test, M.last = 9, M.address1 = 999 woodland, M.zip = 21122, M.emai'at line 5 내 연구에서이 문제는 많은 사람들에게 발생합니다. 코드를 여러 번 바꿨습니다.이 코드는 최신 코드인데도 위와 같은 메시지가 표시됩니다.

이 코드는 아래에 mysql DB를 기록.

도와주세요!

$sql = "UPDATE membership AS M 
     LEFT JOIN address2 AS A2 ON M.memno1 = A2.memno2 
     LEFT JOIN contact AS Con ON M.memno1 = Con.memno3 
     LEFT JOIN workers AS W ON M.memno1 = W.memno4 
     LEFT JOIN comments AS Com ON M.memno1 = Com.memno5"; 
$sql.=" SET (M.first = $first, M.last = $last, M.address1 = $address1,";    
$sql.=" M.zip = $zip, M.email = $email, M.password = $password,"; 
$sql.=" M.secq = $secq,M.seca = $seca,"; 
$sql.=" A2.address2 = $address2,"; 
$sql.=" Con.home = $home, Con.cell = $cell, Con.work = $work,"; 
$sql.=" W.webhelp = $webhelp, W.locorg = $locorg, W.candasst = $candasst,"; 
$sql.=" W.loccam = $loccam, W.other = $other, W.otherexp = $otherexp,"; 
$sql.=" Com.comment = $comment) WHERE memno1=$memno"; 
$result = mysql_query($sql) or die("update for memret 1: ".mysql_error()); 

memno1 최초의 마지막 주소 1 지퍼 이메일 비밀번호 secq 세카 memno2 주소 2 memno3 호 나 전지 작업 memno4 webhelp locorg candasst loccam 다른 otherexp memno5 주석 memno6 사무소 먼저 마지막 주소 1의 주소 2는 압축 (9) 시험 구 999 숲 21122 [email protected] tn9999 집의 잔해 9 덤프 9 1,232,224,444 333,556,666 2,223,335,555 9 예 예 대표 이사 (9) 테스트를 새로운 측면

답변

1

SQL 인풋입니다. 오류 메시지를 올바르게 읽으면 $address1"999 woodland"이며 SQL 구문 분석기에서 올바르게 처리하지 못합니다.

원시 변수를 쿼리 문자열로 대체하는 것을 중지합니다. (그리고 mysql_* 기능도 사용을 중지합니다. 사용되지 않습니다.) 준비된 진술은 먼 길을 갈 것입니다.

// assumes an existing PDO database connection in $conn 
// requires exception-handling code (PDOException) 
// requires you to check that e.g. integer fields will be updated with integers 
$sql = "UPDATE membership AS M 
    LEFT JOIN address2 AS A2 ON M.memno1 = A2.memno2 
    LEFT JOIN contact AS Con ON M.memno1 = Con.memno3 
    LEFT JOIN workers AS W ON M.memno1 = W.memno4 
    LEFT JOIN comments AS Com ON M.memno1 = Com.memno5 
    SET (M.first = :first, M.last = :last, M.address1 = :address1, 
     M.zip = :zip, M.email = :email, M.password = :password, 
     M.secq = :secq, M.seca = :seca, 
     A2.address2 = :address2, 
     Con.home = :home, Con.cell = :cell, Con.work = :work, 
     W.webhelp = :webhelp, W.locorg = :locorg, W.candasst = :candasst, 
     W.loccam = :loccam, W.other = :other, W.otherexp = :otherexp, 
     Com.comment = :comment) WHERE memno1 = :memno"; 
$query = $conn->prepare($sql); 
$params = array(":first" => $first, ":last" => $last, ":address1" => $address1, 
       ":zip" => $zip, ":email" => $email, ":password" => $password, 
       ":secq" => $secq, ":seca" => $seca, 
       ":address2" => $address2, 
       ":home" => $home, ":cell" => $cell, ":work" => $work, 
       ":webhelp" => $webhelp, ":locorg" => $locorg, 
       ":candasst" => $candasst, 
       ":loccam" => $loccam, ":other" => $other, 
       ":otherexp" => $otherexp, 
       ":comment" => $comment, ":memno" => $memno); 
$did_we_succeed = $query->execute($params); 
+0

많은 michaelb958에게 감사드립니다. 나는 당신의 대답에 핵심어로 몇 가지를 보았고 나는 PDO에 대해 완전히 다른 견해를 가지고있었습니다. 나는 나에게 조금 쉬운 길을 가져 갔다. PDO 방식에 대해 배우기 위해 몇 가지 정보를 인쇄했습니다. – oldmanvette

+0

나는 내 코드를 많이 변경 했으므로 새로운 질문을 할 것입니다. 왜냐하면 내가 얻고있는 "바인딩"오류 메시지를 이해하지 못하기 때문입니다. 고마워요 @ michaelb958. 다음 질문에서 당신의 의견을 듣고 싶습니다. – oldmanvette

관련 문제