2012-12-11 2 views
0

이 오류가 계속 발생하지만 부적절한 구문은 볼 수 없지만 어떤 아이디어가 있습니까? 여기에 제 PHP 코드가 있습니다. 다른 모든 페이지가 문제없이 코드를 실행할 수 있으므로 다른 페이지도 정확하다는 것을 알고 있습니다.오류 : SQL 구문에 근처에 '1'에있는 오류가 있습니다.

<?php 

// this connects To database 
$hostname="";  
$username=""; 
$password="";  
$dbname="";  

mysql_connect($hostname,$username,$password) OR DIE ("Connection Failed"); 
mysql_select_db($dbname); 


$action = $_REQUEST["action"]; 
if ($action == 'a') { 
$custFirst = null; 
$custLast = null; 
$custAddress = null; 
$custCity = null; 
$custState = null; 
$custZip = null; 
$custEmail = null; 
$custPhone = null; 
} else { 
$id = $_REQUEST["id"]; 
    $query = "select * from custTab where custNo = $id"; 
    $result = mysql_query($query) 
     or die(mysql_error()); 
    $row = mysql_fetch_array($result); 
    $custFirst = $row['custFirst']; 
    $custLast = $row['custLast']; 
    $custAddress = $row['custAddress']; 
    $custCity = $row['custCity']; 
    $custState = $row['custState']; 
    $custZip = $row['custZip']; 
    $custEmail = $row['custEmail']; 
    $custPhone = $row['custPhone']; 
} // end if 

?> 
+0

'echo $ query;'와 출력을 보여주세요. – MichaelRushton

+4

SQL 주입을 조심하십시오! – Wiseguy

+1

'$ _REQUEST [ "id"]'가 설정되어 있습니까? – Sirko

답변

2

이 위험하고 custNo 필드에 포함 된 내용에 따라 잘못

$query = "select * from custTab where custNo = '$id'"; 
+0

완벽하게 작동했습니다. –

2

시도 $id 주위 quotes 퍼팅 : ID가 정수

$id = $_REQUEST["id"]; 
$query = "select * from custTab where custNo = $id"; 

경우, 당신이해야 사용 :

$id = (int) $_REQUEST["id"]; 
$query = "select * from custTab where custNo = $id"; 

그렇지 않으면 당신은 그것을 인용하고 변수 탈출해야합니다 :

$id = mysql_real_escape_string($_REQUEST["id"]); 
$query = "select * from custTab where custNo = '$id'"; 

을하지만 당신은 정말 모두이 문제를 방지하기 위해 PDO/mysqli과 준비된 문으로 전환해야한다.

관련 문제