#php #mysql #phpmyadmin
Вопрос:
Всем доброе утро
Я пытаюсь обновить таблицу новым выбранным количеством, когда я запускаю следующую функцию, однако я получаю эту ошибку:
Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:xampphtdocsphp_AssessmentsshoppingListmodelfunctions_products.php:11 Stack trace: #0 C:xampphtdocsphp_AssessmentsshoppingListmodelfunctions_products.php(11): PDOStatement->execute() #1 C:xampphtdocsphp_AssessmentsshoppingListcontrollerproduct_update_process.php(21): update_item('57', '3', '1') #2 {main} thrown in C:xampphtdocsphp_AssessmentsshoppingListmodelfunctions_products.ph
Функция обновления количества, function_products.php:
<?php
function update_item($soldID, $orderedQuantity, $itemQuantity)
{
global $conn;
$sql = "UPDATE shopping_items.sold SET orderedQuantity = :itemQuantity WHERE soldID = :soldID";
$statement = $conn->prepare($sql);
$statement->bindValue(':soldID', $soldID);
$statement->bindValue(':orderedQuantity', $orderedQuantity);
$statement->bindValue(':itemQuantity', $itemQuantity);
$result = $statement->execute();
$statement->closeCursor();
return $resu<
}
?>
product_update_process.php
<?php
// Require database connection
require('connection.php');
// Require function
require_once("../model/functions_products.php");
// Fetch the data required
$soldID = $_GET['soldID'];
$itemQuantity = $_POST['itemQuantity'];
$orderedQuantity = $_POST['orderedQuantity'];
if(empty($itemQuantity)) {
echo '<script type="text/javascript">alert("The quantity is required.")</script>' ;
// Redirect the browser window back to the add customer page
echo "<script>setTimeout("location.href = '../index.php';",2000);</script>";
} else {
//call the update_item() function
$result = update_item($soldID, $itemQuantity, $orderedQuantity);
// Redirect the browser window back to the admin page
header("location: ../index.php");
}
?>
В чем здесь может быть проблема?
Спасибо за вашу помощь.
Комментарии:
1. Внимательно прочитайте сообщение об ошибке, а затем проверьте свой код. Вы привязываете три значения к подготовленному утверждению, но в вашем заявлении есть только два заполнителя.
2. Чтобы добавить комментарий к @TangentiallyPerpendicular, почему вы привязываетесь к
orderedQuantity
нему ?
Ответ №1:
Чтобы добавить комментарий @TangentiallyPerpendicular, почему вы привязываетесь к :orderedQuantity
нему ? Эта переменная не используется в вашем SQL-операторе, даже если вы сказали механизму SQL ожидать эту переменную. Столбцу не обязательно быть переменной, чтобы передать ей переменную.
Комментарии:
1. Спасибо вам за вашу помощь, я решил эту проблему, не связывая заказанное количество