【发布时间】:2014-01-22 02:46:07
【问题描述】:
我收到以下警告
警告:PDOStatement::execute(): SQLSTATE[HY093]: 无效参数号:绑定变量的数量与第 29 行 C:\xampp\htdocs\form\formProcess.php 中的标记数量不匹配
我的代码如下:
<?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>
为什么会出现此错误?我看过了,无法确定错误。
【问题讨论】: