简体   繁体   English

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

[英]PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number:

I'm getting the error "SQLSTATE[HY093]: Invalid parameter number" when I try to run this query: 尝试运行此查询时,出现错误“ SQLSTATE [HY093]:无效的参数号”:

<?php
include "../config/c_config.php";
$db = dbConn::getConnection();

$pmuid = $_POST['txtuid'];
$pnml = $_POST['txtnm'];
$ptgll = $_POST['txttgl'];
$jk = $_POST['optjk'];
$palamat = $_POST['txtalamat'];
$idv = $_POST['cbprov'];
$idc = $_POST['cbcity'];
$pkode = $_POST['txtkodepos'];
$pphone= $_POST['txtnophone'];
$pemkof= $_POST['txtmailinf'];
$pimg = $_POST['fileimg'];
$pdate=date("Y-m-d H:i:s");

// Update data on mysql
$sqlep = "UPDATE str_user_mamber_profile SET
profile_nama_lengkap=:pnml,
profile_jk=:jk,
profile_tgl_lahir=:ptgll,
profile_alamat=:palamat,
id_provinsi=:idv,
id_city=:idc,
profile_kodepos=:pkode,
profile_phone=:pphone,
profile_email_konfirmasi=:pemkof,
profile_date=:pdate 
WHERE mamber_unique_id = :pmuid";

$qep = $db->prepare($sqlep);
$qep->execute(array(":pnml"=>$pnml,
                    ":jk"=>$jk,
                    ":ptgll"=>$ptgll,
                    ":palamat"=>$palamat,
                    ":idv"=>$idv,
                    ":idc"=>$idc,
                    ":pkode"=>$pkode,
                    ":pphone"=>$pphone,
                    ":pemkof"=>$pemkof,
                    ":pdate"=>$pdate,
                    ":pmuid"=>$pmuid));
if($qep){
    echo 'work';
}else{
    echo 'not work';
}
?>

after i run,this query give a result "WORK" but not update the db. 运行后,此查询给出结果“ WORK”,但不更新数据库。 i try search same question about this error but not help me to fixed. 我尝试搜索有关此错误的相同问题,但无法帮助我解决。 can you help me see what is wrong with the query? 您能帮我看看查询出了什么问题吗?

Thank you 谢谢

change 更改

":pnml"=>$pnml,

to

"pnml"=>$pnml,

everywhere in "execute" method 处处采用“执行”方法

$qep->execute(array("pnml"=>$pnml,
                    "jk"=>$jk,
                    "ptgll"=>$ptgll,
                    "palamat"=>$palamat,
                    "idv"=>$idv,
                    "idc"=>$idc,
                    "pkode"=>$pkode,
                    "pphone"=>$pphone,
                    "pemkof"=>$pemkof,
                    "pdate"=>$pdate,
                    "pmuid"=>$pmuid));

$qep is a statement object, and will always be truthy. $qep是一个语句对象,并且永远是真实的。 You need to capture the result of executing the statement: 您需要捕获执行语句的结果

$result = $qep->execute(...);
if ($result){
    echo 'work';
} else {
    echo 'not work';
    var_dump($qep->errorInfo());
}

Using $_POST values without checking that they are set may give you lots of warnings, as well. 使用$_POST值而不检查是否已设置它们也会给您很多警告。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命错误:消息中出现“ SQLSTATE [HY093]:无效的参数编号:未定义参数”的未捕获异常“ PDOException” - Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' in 致命错误:带有消息&#39;SQLSTATE [HY093]的未捕获异常&#39;PDOException&#39;:参数号无效:没有参数被绑定 - Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: no parameters were bound PHP PDO SQL错误:带有消息&#39;SQLSTATE [HY093]的未捕获异常&#39;PDOException&#39;:参数号无效 - PHP PDO SQL error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number 致命错误:未捕获的异常 &#39;PDOException&#39; 带有消息 &#39;SQLSTATE[HY093]:参数无效 - Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter 消息“ SQLSTATE [HY093]”的异常“ PDOException”:参数号无效 - exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number 绑定参数错误:致命错误:未捕获的 PDOException:SQLSTATE[HY093]:无效的参数号:未定义参数 - Binding parameters error:Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in 致命错误:未捕获的 PDOException:SQLSTATE[HY093]:无效参数号:未定义参数 - Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined 消息为&#39;SQLSTATE [HY093]:未捕获的异常&#39;PDOException&#39;:无效的参数号:未定义参数&#39; - Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' php 错误:致命错误:未捕获 PDOException:SQLSTATE[HY093]:无效参数号:绑定变量数与令牌数不匹配 - php error : Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens 致命错误:未捕获的 PDOException:SQLSTATE[HY093]:无效的参数号: - Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number:
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM