Excepción no detectada DOP
-
26-09-2019 - |
Pregunta
Este error aparece cuando se ejecuta el código de abajo:
Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[42000]: Syntax error or access violation: 1065 Query was empty'
in /home/content/63/6563663/html/inventory/pg.php:20
Stack trace:
#0 /home/content/63/6563663/html/inventory/pg.php(20): PDOStatement->execute()
#1 {main} thrown in /home/content/63/6563663/html/inventory/pg.php on line 20
<?php
$u=$_GET["u"];
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {
$amount = isset($_POST['amount']) ? $_POST['amount'] : null;
if (null != $amount) {
$user = 'username';
$pass = 'password';
$pdo = new PDO('mysql:host=localhost', $user, $pass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
session_start();
$tablename = $_SESSION['MM_Username'];
$query = sprintf("UPDATE `%s` SET `stock` = :amount WHERE `itemname` = :u ", $tablename);
$stmt = $pdo->prepare($query);
$stmt->bindParam('amount', $amount);
$stmt->execute();
}
}
?>
Las obras pero ahora con este error. Me disculpo como yo soy nuevo en DOP.
Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens'
in /home/content/63/6563663/html/inventory/pg.php:20
Stack trace:
#0 /home/content/63/6563663/html/inventory/pg.php(20): PDOStatement->execute()
#1 {main} thrown in /home/content/63/6563663/html/inventory/pg.php on line 20
No hay solución correcta
Otros consejos
Probablemente debería familiarizarse con try
ing y catch
ing excepciones .
Bueno, el mensaje de error es bastante claro:
1.065 consultas estaba vacía
se utiliza el $UpdateQuery
variable, que no existe. Probablemente quería decir
$stmt = $pdo->prepare($query);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow