2016-09-05 3 views
-3

이 내 코드입니다 :SQLSTATE [HY093]

if (!isset($_POST['cellulare'])) $cell = "-"; else $cell = $_POST['cellulare']; 
if (!isset($_POST['ufficio'])) $uff = "-"; else $uff = $_POST['ufficio']; 
if (!isset($_POST['email'])) $email = "-"; else $email= $_POST['email']; 

$sqlup = "UPDATE rubrica SET nome = :nm, 
      cognome = :cgm, 
      mail = :email, 
      cellulare = :cell, 
      ufficio = :office, 
      WHERE id=".$_GET['mod']; 
$stmt = $pdo->prepare($sqlup); 
$stmt->bindParam(':nm', $_POST['nome'], PDO::PARAM_STR);         
$stmt->bindParam(':cgm', $_POST['cognome'], PDO::PARAM_STR);  
$stmt->bindParam(':email ', $email, PDO::PARAM_STR); 
$stmt->bindParam(':cell', $cell, PDO::PARAM_STR); 
$stmt->bindParam(':office', $uff, PDO::PARAM_STR); 
$stmt->execute(); 

분명히 오류가없는,하지만 난이 얻을 :

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined'

+1

'$ _GET [ 'mod']'은 (는) 비어 있지 않으며 정수를 포함합니까? – Legionar

+2

왜'$ _GET [ 'mod']'를 바인딩하지 않습니까? 'email' 바인딩은 이름에 여분의 공백이 있습니다. – chris85

+1

왜 당신은 또한'id = "를 매개 변수화하고 바인딩하지 않습니까? $ _ GET [ 'mod']'당신의 스크립트는 [SQL Injection Attack]의 위험이 있습니다. (http://stackoverflow.com/questions/60174/how-can -i-prevent-sql-injection-in-php) [Little Bobby Tables] (http://bobby-tables.com/)에 무슨 일이 있었는지 살펴보기 [입력을 탈출하고 있다면, 안전하지 않은 !] (http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) [준비된 매개 변수가있는 문] (http://php.net/manual /en/mysqli.quickstart.prepared-statements.php) – RiggsFolly

답변

2

당신에게 $_GET['mod']이 비어 있지 및 정수를 포함 하시겠습니까?

$sqlup = "UPDATE rubrica SET nome = :nm, 
     cognome = :cgm, 
     mail = :email, 
     cellulare = :cell, 
     ufficio = :office 
     WHERE id=".$_GET['mod']; 

또한 당신의 email 바인딩에 오류가가, 추가가 :

$sqlup = "UPDATE rubrica SET nome = :nm, 
     cognome = :cgm, 
     mail = :email, 
     cellulare = :cell, 
     ufficio = :office, /* <== here */ 
     WHERE id=".$_GET['mod']; 

이로 변경을 - 예, 다음 SQL 또 다른 오류가 있으면 당신은 거기 ,WHERE 전에이 공간은 @ chris85 언급했다.

$stmt->bindParam(':email', $email, PDO::PARAM_STR); 
+1

만약 당신이 PDO를 사용하지 않는다면 GET의 값을 SQL 문자열에 넣지 마십시오! – cmnardi

+1

그래, 그게 위의 내 의견이다 – Legionar

+1

고맙다. WHERE 문 앞에 쉼표를 사용합니다. 이것은 몇 시간 연속으로 작업 할 때 발생합니다 ... : D 또한 WHERE id를 변경했습니다. = : id, @ cmnardi 제안대로 – Tony33

관련 문제