Reputation: 4163
I am getting the following warning
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\xampp\htdocs\form\formProcess.php on line 29
My code is below:
<?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 file
<!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>
Why am I getting this error? I have looked at it and can't determine an error.
Upvotes: 1
Views: 68
Reputation: 473
Change 'value' singular into 'values' plural in your sql statements.
Upvotes: 1
Reputation: 68476
You missed the colons here on your second INSERT Statement.
name, :lastName, email, position)");
---^ --^
Upvotes: 4
Reputation: 626
Looks like a typo maybe, this line:
$stmt = $DB->prepare("INSERT INTO personalInfo (id, Company_id, firstName, lastName, email, position) value (:id, :Company_id, :firstName, :lastName, email, position)");
should be
$stmt = $DB->prepare("INSERT INTO personalInfo (id, Company_id, firstName, lastName, email, position) value (:id, :Company_id, :firstName, :lastName, :email, :position)");
Upvotes: 3
Reputation: 360672
Your forgot some :
:
$stmt = $DB->prepare("[...snip...] :lastName, email, position)");
^-- ^---
so when you try to bind to :email
and :position
, which don't exist, you get your error message.
Upvotes: 2