无法运行查询:SQLSTATE [HY093]:参数号无效:绑定变量数与令牌数不匹配 [英] Failed to run query: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

查看:64
本文介绍了无法运行查询:SQLSTATE [HY093]:参数号无效:绑定变量数与令牌数不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是php的新手,并试图摆脱这个错误一段时间了。我相信我有正确数量的参数,但无法找出问题所在。这是我下面的PHP代码..任何答案都非常感谢。谢谢



I am a newbie to php and been trying to get rid of this error for a while now. I believe i have the correct amount of parameters but cant figure out where the problem is. This is my php code below.. any answer is much appreciated. thanks

<?php
/*
 * Created on Oct 10, 2013
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 require ("common.php");
 
 //$mySessionName = $_SESSION['UserName'];
 	if (isset($_POST['Add'])){
		
		$mySession = $_SESSION['user']['FullName']; //get the current user
		
		//mysql_select_db("tech_debt") or die("Could not connect to the database..".mysql_error());
		$query = "INSERT INTO compliance_requirement (ComplianceID, ComplianceName, ComplianceGoal, ComplianceDescription, ComplianceStartDate, ComplianceEndDate, UserName)
				VALUES (NULL, :ComplianceName, :ComplianceGoal, :ComplianceDescription, :ComplianceStartDate, :ComplianceEndDate, :UserName)";
		
		
		$query_params = array(
			':ComplianceID' => '',
            ':ComplianceName' => $_POST['ComplianceName'],
            ':ComplianceGoal' => $_POST['ComplianceGoal'],
            ':ComplianceDescription' => $_POST['ComplianceDescription'],
            ':ComplianceStartDate' => $_POST['ComplianceStartDate'],
            ':ComplianceEndDate' => $_POST['ComplianceEndDate'],
            ':UserName' => $_POST['UserName']
        );

		try
        {
            // Execute the query to create the compliance
            $stmt = $db->prepare($query);
            $result = $stmt->execute($query_params);
        }
        catch(PDOException $ex)
        {
            die("Failed to run query: " . $ex->getMessage()); 
        } 
         
        // This redirects the user back to the login page after they register 
        header("Location: createcompliance.php"); 
	}
?>

推荐答案

mySessionName =
mySessionName =


_SESSION ['UserName'];
if (isset(
_SESSION['UserName']; if (isset(


_POST [' 添加'])){

_POST['Add'])){


这篇关于无法运行查询:SQLSTATE [HY093]:参数号无效:绑定变量数与令牌数不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆