0

我是 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");
}
?>
4

2 回答 2

0

您在查询中的变量:compName, :compGoal, :compDes, :compStart, :compEnd, :$mySessionName

与您的参数数组中的名称不同:

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

看 :

:compName <> :ComplianceName
:compGoal <> :ComplianceGoal
...
于 2013-10-17T15:06:29.153 回答
0

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

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

compName 和 ComplianceName 是两个非常不同的字符串。

于 2013-10-17T15:03:52.387 回答