当我尝试运行此查询时,我收到错误“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';
}
?>
运行后,此查询给出结果“WORK”但不更新db。我尝试搜索有关此错误的相同问题但不帮助我修复。你能帮我看看查询有什么问题吗?
谢谢
答案 0 :(得分:0)
变化
":pnml"=>$pnml,
到
"pnml"=>$pnml,
&#34;执行&#34;方法
$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));
答案 1 :(得分:0)
$qep
是一个声明对象,并且永远是真实的。您需要捕获执行语句的结果:
$result = $qep->execute(...);
if ($result){
echo 'work';
} else {
echo 'not work';
var_dump($qep->errorInfo());
}
使用$_POST
值而不检查它们是否已设置可能会给您提供大量警告。