2011-07-26 4 views
1
$tran = "START TRANSACTION;"; 

    $tran_res = mysql_query($tran); 

    $qry_1 = "INSERT INTO docList (doc_ip , doc_country , doc_ref) VALUES ('$ip' , '$country' , '$http_ref');"; 
    $res_1 = mysql_query($qry_1); 
    if(!$res_1) 
     die ("qry1 fail " . mysql_error()); 

    $ins_id = mysql_insert_id(); 
    if(!$ins_id) 
     die ("ins id fail " . mysql_error()); 
    echo "<b>$ins_id</b>"; 

    $qry_2 = "INSERT INTO docContent (doc_id , cont_date , cont_title , cont_aim , cont_obj , cont_theory , cont_sw , cont_code) VALUES ('$ins_id' , '$dt' , '$title' , '$aim' , '$obj' , '$th' , '$sw' , '$code');"; 

    $res_2 = mysql_query($qry_2); 
    if(!$res_2) 
     die("qry2 fail " . mysql_error()); ` 

위의 다음과 같은 오류를 반환의 실행 :PHP - MySQL의 트랜잭션 실행 오류

2 qry failYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'login'); if($query->num_rows()>0) return $query->result_array(); } ' at line 1

$qry_2의 실행이 실패 효과에

,하지만 난 그것이 오류에 의해 당황하고 보여주는 (에러 노트에 언급 된 바와 같은 라인 1에는 그런 코드가 없다). 또한 쿼리 ($qry_2)는 MySql 콘솔에서 제대로 실행됩니다.

+1

보인다. – JJJ

+0

@Juhana 당신이 옳습니다! 지금 일하고있어. – AFV

답변

1

MySQL 서버에서받은 실제 쿼리를 게시하지 않았지만 mysql_real_escape_string()을 SQL에 삽입하는 데 사용하지 않았다고 말할 수 있습니다.

는 (당신은 데이터베이스에 PHP 코드를 삽입하려고합니까?) 당신이 당신의 변수를 살균하지 않는 것처럼

+0

예 쿼리의 코드는 모든 언어에서 올 수 있으며 물론 mysql_escape_ *를 사용하여 'sanitization'후 치료되었습니다. – AFV

+0

감사합니다! 메모 용. – AFV

2

$qry_2의 내용을 출력하여 실제 SQL 문이 실행되는지 확인하십시오. SQL 인젝션 취약점이있을 확률이 높습니다. 삽입하려는 변수 중 하나에 적어도 '이 포함되어 구문 오류가 발생합니다.

당신이 MUSTmysql_real_escape_string()을 통해 변수를 전달,

'O' - string containing the letter "O" 
Reilly - a field named "Reilly", with no operator between this "field" and the "O" previous 
'); - a weird unterminated string, also with no operator between this and the previous field. 

이 해결하기 위해 : 당신이

$var = "O'Reilly"; 
$sql = "INSERT INTO names (name) VALUES ('$var')"; 

이있는 경우로 해석됩니다

INSERT INTO names (name) VALUES ('O'Reilly'); 

될 겁니다 이러한 오류가 발생하는 것을 방지합니다. O'ReillyO\'Reilly으로 설정되며 이는 쿼리에서 "안전"합니다.