2014-01-21 100 views
1

我收到以下警告越来越PDO MySQL错误

警告:PDOStatement对象::执行():SQLSTATE [HY093]:无效的参数编号:绑定变量的数目不C匹配的令牌数量: \ XAMPP \ htdocs中\表格\ formProcess.php上线29

我的代码如下:

<?php 
require_once 'DB.php'; 

//Peronal Info DB 
$firstName = $_POST['firstName']; 
$lastName = $_POST['lastName']; 
$email = $_POST['email']; 
$position = $_POST['position']; 
$id = 1; 
//Company Info DB 
$companyName = $_POST['companyName']; 
//$address = $_POST['address']; 
//$city = $_POST['city']; 
//$state = $_POST['state']; 
//$zip = $_POST['zip']; 
//$phone = $_POST['phone']; 





//INSERT INTO COMPANIES TABLE 
$stmt = $DB->prepare("INSERT INTO companies (CompanyName) value (:Company_id"); 
$stmt->execute(array(':Company_id' => $companyName)); 


//INSERT INTO PERSONAL INFO TABLE 
$stmt = $DB->prepare("INSERT INTO personalInfo (id, Company_id, firstName, lastName, email, position) value (:id, :Company_id, :firstName, :lastName, email, position)"); 
$stmt->execute(array(':id' => $id, ':Company_id' => $companyName, ':firstName' => $firstName, ':lastName' => $lastName, ':email' => $email, ':position' => $position)); 

echo "Form proccessed successfully $firstName $lastName $email $companyName $position!"; 

?> 

HTML文件

<!DOCTYPE html> 
<html> 
    <head> 
     <title></title> 
     <link rel="stylesheet" type="text/css" href="style.css"> 
    </head> 
<body> 
    <div class="container"> 
     <form action="formProcess.php" method="post"> 
      <label for="firstName" class="formLabel">First Name:</label> 
       <input type="text" name="firstName" id="firstName" /> 
      <label for="lastName" class="formLabel">Last Name:</label> 
       <input type="text" name="lastName" id="lastName" /> 
      <label for="companyName" class="formLabel">Company Name:</label> 
       <input type="text" name="companyName" id="companyName" /> 
      <label for="position" class="formLabel">Position:</label> 
       <input type="text" name="position" id="position" /> 
      <label for="email" class="formLabel">Email:</label> 
       <input type="text" name="email" id="email" /> 
      <input type="submit" value="Submit Form" /> 
     </form> 
    </div> 
</body> 

</html> 

为什么我得到这个错误?我已经看过它,不能确定一个错误。

回答

4

你错过了冒号在这里你的第二个INSERT语句。

name, :lastName, email, position)"); 
      ---^ --^ 
2

你忘记一些:

$stmt = $DB->prepare("[...snip...] :lastName, email, position)"); 
               ^-- ^--- 

所以当你尝试绑定到:email:position,它不存在,你会得到你的错误消息。

3

看起来像一个错字,也许,这条线:

$stmt = $DB->prepare("INSERT INTO personalInfo (id, Company_id, firstName, lastName, email, position) value (:id, :Company_id, :firstName, :lastName, email, position)"); 

应该

$stmt = $DB->prepare("INSERT INTO personalInfo (id, Company_id, firstName, lastName, email, position) value (:id, :Company_id, :firstName, :lastName, :email, :position)"); 
1

在您的sql语句中将'value'单数变成'values'复数。