SQLSTATE [HY093]

时间:2016-09-05 14:07:18

标签: php sql pdo

这是我的代码:

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(); 

显然没有错误,但我明白了:

  

致命错误:未捕获异常'PDOException',消息为'SQLSTATE [HY093]:参数号无效:参数未定义'

1 个答案:

答案 0 :(得分:2)

您确定$_GET['mod']不为空且包含整数吗?如果是,那么您的SQL中还有另一个错误 - 您在,之前有WHERE

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

将其更改为:

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

你的绑定email也有错误,@ chris85提到了额外的空格。

$stmt->bindParam(':email', $email, PDO::PARAM_STR);
相关问题