简体   繁体   English

消息为“ SQLSTATE [HY093]”的未捕获异常“ PDOException”。 我不明白怎么了

[英]Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]. I don't understand what's wrong

the backend part: 后端部分:

$producttitle = $_POST['product-title'];
$price = $_POST['price'];
$category = $_POST['Category'];
$file = $_FILE['file_upload'];
$description = $_POST['description'];

$adq = "INSERT INTO Advertenties (Titel, Prijs, Categorie, Image, Beschrijving) VALUES (:product-title, :price, :category, :file_upload, :description);";

$query = $GLOBALS['$odb']->prepare($adq);


$results = $query->execute(array(       
    ":product-title" => $producttitle,
    ":price" => $price,
    ":category" => $category,
    ":file_upload" => $file,
    ":description" => $description
    ));

Front end: 前端:

 <?php
require_once('../classes/layout_shared.php');

?>

<html lang="NL">
    <head>
        <meta charset="UTF-8">
        <link rel="stylesheet" href="../css/bootstrap.css">
    </head>
    <body>
        <div class="container">
            <div class="col-md-9">
                <form method="POST" action="../classes/upload.php" class="ad-form" enctype="multipart/form-data">
                    <lable>Titel</lable>
                        <input class="form-control" type="text" name="product-title"/>
                   <lable>Bedrag/Bieden vanaf:</lable>
                        <input class="form-control" type="text" name="price"/><br>
                        <lable>Categorie</lable>
                        <input class="form-control" type="" name="category"/><br>
                   <lable>Image</lable>
                        <input class="form-control" type="file" name="file_upload"/> <br>
                   <lable>Beschrijving:</lable>
                       <textarea class="form-control" placeholder="Voeg een beschrijving van het product toe" name="description"></textarea></br>
                   <input type="submit" name="toevoegen" value="Toevoegen"/>
                </form> 
            </div>
        </div>
    </body>
</html>

So, this is my code above. 所以,这是我上面的代码。 It's for some reason giving me an error but I just can't undertand why. 由于某种原因给我一个错误,但我无法理解为什么。 I've scoured the internet, and all I can find is something doesn't match something. 我搜寻了互联网,发现的所有东西都不匹配。 I've gone through this so many times, its starting to annoy me now. 我经历了这么多次,现在开始惹恼我。

Any ideas? 有任何想法吗?

尝试用:product_title替换:product-title

When in doubt, break your query into as many lines as possible so that you can sniper the issue rather than having MySQL always report an error on line 1: 如有疑问,请将查询分成尽可能多的行,以便您可以狙击问题,而不是让MySQL始终在第1行报告错误:

Turn

$adq = "INSERT INTO Advertenties (Titel, Prijs, Categorie, Image, Beschrijving) VALUES (:product-title, :price, :category, :file_upload, :description);";

Into

$adq = "INSERT INTO Advertenties
        (Titel,
        Prijs,
        Categorie,
        Image,
        Beschrijving)
        VALUES
        (:product-title,
        :price,
        :category,
        :file_upload,
        :description);";

Also, is :product-title a valid placeholder? 另外, :product-title是有效的占位符吗?

Beyond the sql placeholder name problem, you have multiple OTHER bugs: 除了sql占位符名称问题之外,您还有多个其他错误:

Field names are case sensitive: 字段名称区分大小写:

$category = $_POST['Category'];
                    ^---
<input class="form-control" type="" name="category"/><br>
                                          ^----

$_FILES is an array of arrays: $ _FILES是一个数组数组:

$file = $_FILE['file_upload'];
":file_upload" => $file,

You can NOT bind array to a query placeholder. 您不能将数组绑定到查询占位符。 No idea what you're trying to do here - insert the actual file contents, or just the name of the file? 不知道您要在这里做什么-插入实际文件内容,还是仅输入文件名? Either way, it should be something like 无论哪种方式,它都应该像

":file_upload" => $file['tmp_name'],

to bind only one particular value out of the array. 只能将一个特定值绑定到数组之外。

instead of having the array as a parameter for the execute function you should bind all the values separately using bindValue. 而不是将数组作为execute函数的参数,您应该使用bindValue分别绑定所有值。 If you passed them as a parameter every value would be treated as a string, with bindValue you maintain the type of the variable. 如果将它们作为参数传递,则每个值都将被视为字符串,使用bindValue可以维护变量的类型。 The code would look something like this: 代码看起来像这样:

$adq = "INSERT INTO Advertenties (Titel, Prijs, Categorie, Image, Beschrijving) VALUES (:product-title, :price, :category, :file_upload, :description);";
$query = $GLOBALS['$odb']->prepare($adq);
$query->bindValue(":product-title", $producttitle);
$query->bindValue(":price", $price);
$query->bindValue(":category", $category);
$query->bindValue(":file_upload", $file);
$query->bindValue(":description", $description);
$result = $query->execute();

I hope that this helps. 我希望这个对你有用。

Succes gewenst 成功gewenst

looks like you have $category = $_POST[' Category ']; 看起来您有$ category = $ _POST [' Category ']; when you are sending 'category'. 当您发送“类别”时。 This is causing an undefined index. 这导致未定义的索引。 lowercase the c. 小写的c。 Along with Alex answer and you should be good 随着亚历克斯回答,你应该很好

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHP AJAX - 未捕获的 PDOException:SQLSTATE[HY093],这是什么? - PHP AJAX - Uncaught PDOException: SQLSTATE[HY093], what is this? 致命错误:消息中出现“ SQLSTATE [HY093]:无效的参数编号:未定义参数”的未捕获异常“ PDOException” - Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' in 消息为“ SQLSTATE [HY093]:参数号无效”的未捕获异常“ PDOException” - Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number' 消息“ SQLSTATE [HY093]”的异常“ PDOException”:参数号无效 - exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number PHP致命错误:消息为&#39;SQLSTATE [HY093]的未捕获异常&#39;PDOException&#39;:无效的参数编号: - PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: 消息“ SQLSTATE [HY093]”的未捕获异常“ PDOException”:从数据库中获取信息时 - Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: while getting information out of the database 消息为&#39;SQLSTATE [HY093]:未捕获的异常&#39;PDOException&#39;:无效的参数号:未定义参数&#39; - Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' 致命错误:未捕获的异常 &#39;PDOException&#39; 带有消息 &#39;SQLSTATE[HY093]:参数无效 - Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter PHP PDO SQL错误:带有消息&#39;SQLSTATE [HY093]的未捕获异常&#39;PDOException&#39;:参数号无效 - PHP PDO SQL error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number 致命错误:带有消息&#39;SQLSTATE [HY093]的未捕获异常&#39;PDOException&#39;:参数号无效:没有参数被绑定 - Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: no parameters were bound
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM