我是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");
}
?>
答案 0 :(得分:0)
很多问题。 1.您正在查询中间 2.
$sql = "VALUES (:compName, ...";
$query_paramsm = array(':ComplianceName' => $_POST['compName'] ...);
compName和ComplianceName是两个非常不同的字符串。
答案 1 :(得分:0)
您在查询:compName, :compGoal, :compDes, :compStart, :compEnd, :$mySessionName
与param数组中的名称不同:
array(':ComplianceName' => $_POST['compName'], ':ComplianceGoal'=>$_POST['compGoal'], 'ComplianceDescription' => $_POST['compDes'], 'ComplianceStartDate'=>$_POST['compStart'], 'ComplianceEndDate'=>$_POST['compEnd'], 'UserName'=>$_POST['UserName'])
看:
:compName <> :ComplianceName
:compGoal <> :ComplianceGoal
...