致命错误:未捕获的PDOException:SQLSTATE [42S22]:找不到列:1054未知列

时间:2019-06-20 16:37:40

标签: php sql

所以我有以下代码,并且出现错误致命错误:

  

未捕获的PDOException:SQLSTATE [42S22]:找不到列:1054未知   的“ where子句”中的“ djklhawjoDfe”列   C:\ wamp64 \ www \ warehouse \ add-pack.php在第43行

在同一页面中,我试图将product_pack_name列中的值添加到名为product_pack_name的表“ product_pack”中,然后获取ID,该ID将自动递增回到此页面

我在做什么错了?

<h3>Warehouse Management CRUD Application - UNIWA Database II lab</h3>

<h4>Δημιουργήστε ένα Νέο Πακέτο!</h4>
<form id="addCategory" method="POST">
    <table border="1" cellpadding="10">
        <tr align='center'>
            <td>Name</th>
            <td><input name="product_pack_name" type="text" value=""/></td>
        </tr>
    </table>
    <input type='submit' name='submit' value='Submit'/>
    </form>

    <?php
   require 'database.php';
   if(isset($_POST["submit"]))
   {
        if ( !empty($_POST["product_pack_name"])) 
    {
        $product_pack_name = $_POST['product_pack_name'];

        // create a product pack
        $pdo = Database::connect();
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $mpla = "INSERT INTO product_pack (product_pack_name) values (?)";

        $result = $pdo->prepare($mpla);
        $result->execute(array($product_pack_name));

        $sql = $pdo->query("SELECT * FROM product_pack WHERE product_pack_name = $product_pack_name"); 


        echo "$product_pack_name";




        while ($rows = $sql->fetch(PDO::FETCH_ASSOC))
                    {
                        $row2 = $rows['product_pack_id'];
                        $row1 = $rows['product_pack_name'];
                        echo '<p> Success </p>';
                    echo '<h2>Pack name '. $row1['product_pack_name'] .' added in the database</h2>';
                    echo '<h3>Press Continue to Select Products for the pack <h3>';
                    echo '<button type="button" onclick="viewProduct('.$row2['product_pack_id'].')">view</button>';
                    }

                    Database::disconnect();



    }
    else 
    {
        echo 'Add pack name to continue';
    }

}
?>

0 个答案:

没有答案