gpt4 book ai didi

php - 获取 pdo mysql 错误

转载 作者:行者123 更新时间:2023-11-29 03:52:20 25 4
gpt4 key购买 nike

我收到以下警告

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

我的代码如下:

<?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>

为什么会出现此错误?我已经看过了,无法确定错误。

最佳答案

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

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

关于php - 获取 pdo mysql 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21266473/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com