gpt4 book ai didi

php - 无法运行查询 : SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

转载 作者:行者123 更新时间:2023-11-30 01:11:38 26 4
gpt4 key购买 nike

我是 php 的新手,现在一直在尝试摆脱这个错误。我相信我有正确数量的参数,但无法弄清楚问题出在哪里。这是我下面的 php 代码..非常感谢任何答案。谢谢

require ("common.php");
$mySessionName = $_SESSION['user']['UserName'];
if(!empty($_POST)){
$sql = "INSERT INTO compliance_requirement(ComplianceName, ComplianceGoal, ComplianceDescription, ComplianceStartDate, ComplianceEndDate, UserName)''VALUES (:compName, :compGoal, :compDes, :compStart, :compEnd, :$mySessionName)";

$query_paramsm = array(':ComplianceName' => $_POST['compName'], ':ComplianceGoal'=>$_POST['compGoal'], 'ComplianceDescription' => $_POST['compDes'], 'ComplianceStartDate'=>$_POST['compStart'], 'ComplianceEndDate'=>$_POST['compEnd'], 'UserName'=>$_POST['UserName']);

try{
$stmt = $db->prepare($sql);
$result = $stmt->execute($query_paramsm);
}
catch(PDOException $ex)
{

die("Failed to run query: " . $ex->getMessage());
}
header("Location: compliance.php");
}
?>

最佳答案

很多问题。1. 查询中间有 ''2.

$sql = "VALUES (:compName, ...";
$query_paramsm = array(':ComplianceName' => $_POST['compName'] ...);

compName 和ComplianceName 是两个截然不同的字符串。

关于php - 无法运行查询 : SQLSTATE[HY093]: Invalid parameter number: parameter was not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19430305/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com