bind_param警告变量数和参数数不匹配

klh5stk1  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(425)

**结案。**此问题不可复制或由打字错误引起。它目前不接受答案。
**想改进这个问题吗?**更新问题,使其成为堆栈溢出的主题。

10个月前关门了。
改进这个问题
当我去编辑除图像和链接以外的任何内容时,我会得到这个错误“”,尽管它仍然会更新项目并将其作为新的更新信息显示在我的产品列表中。参数和变量匹配,我已经计算过很多次了,我开始认为代码中还有其他东西。
在此处输入图像描述
在此处输入图像描述
这是我编辑页面的代码:

<?php 

require_once 'connect.php';

require_once 'header.php';

?>
<!DOCTYPE html>
<html>
<head>
<script src="//cdn.ckeditor.com/4.5.5/standard/ckeditor.js"></script>   
</head>
<body>
<div class="container">
    <?php 
    if(isset($_POST['update'])){

        if( empty($_POST['category']) || empty($_FILES['image']) ||  empty($_POST['productname']) || empty($_POST['price']) || empty($_POST['description']) || empty($_POST['details']) || empty($_POST['spec_1']) || empty($_POST['spec_2']) || empty($_POST['spec_3'])|| empty($_POST['spec_4']) || empty($_POST['spec_5']) || empty($_POST['spec_6']) || empty($_POST['spec_7']) || empty($_POST['spec_8']) || empty($_POST['spec_9']) || empty($_POST['spec_10']) || empty($_POST['info_1']) || empty($_POST['info_2']) || empty($_POST['info_3'])|| empty($_POST['info_4']) || empty($_POST['info_5']) || empty($_POST['info_6']) || empty($_POST['info_7']) || empty($_POST['info_8']) || empty($_POST['info_9']) || empty($_POST['info_10']) || empty($_FILES['link_1'])  )
        {
            echo "Please fillout all required fields"; }

            $category  = $_POST['category'];
            $image = $_FILES['image']['name'];
            $productname = $_POST['productname'];
            $price  = $_POST['price'];
            $description  = $_POST['description'];
            $details = $_POST['details'];
            $spec_1 = $_POST['spec_1'];
            $spec_2 = $_POST['spec_2'];
            $spec_3 = $_POST['spec_3'];
            $spec_4 = $_POST['spec_4'];
            $spec_5 = $_POST['spec_5'];
            $spec_6 = $_POST['spec_6'];
            $spec_7 = $_POST['spec_7'];
            $spec_8 = $_POST['spec_8'];
            $spec_9 = $_POST['spec_9'];
            $spec_10 = $_POST['spec_10'];
            $info_1 = $_POST['info_1'];
            $info_2 = $_POST['info_2'];
            $info_3 = $_POST['info_3'];
            $info_4 = $_POST['info_4'];
            $info_5 = $_POST['info_5'];
            $info_6 = $_POST['info_6'];
            $info_7 = $_POST['info_7'];
            $info_8 = $_POST['info_8'];
            $info_9 = $_POST['info_9'];
            $info_10 = $_POST['info_10'];
            $link_1 = $_FILES['link_1']['name'];

        if ((!($_FILES['image']['name'])) && (!($_FILES['link_1']['name'])) ) {
        $sql = $con->prepare("UPDATE products SET category = ?, productname = ?, price = ?, description = ?, details = ?, spec_1 = ?, spec_2 = ?, 
        spec_3 = ?, spec_4 = ?, spec_5 = ?, spec_6 = ?, spec_7 = ?, spec_8 = ?, spec_9 = ?, spec_10 = ?, info_1 = ?, info_2 = ?,
        info_3 = ?, info_4 = ?, info_5 = ?, info_6 = ?, info_7 = ?, info_8 = ?, info_9 = ?, info_10 = ? WHERE product_id = ?");
        $sql->bind_param("sssssssssssssssssssssssssi",$category, $productname, $price, $description, $details, $spec_1, $spec_2, $spec_3, $spec_4, $spec_5, $spec_6, $spec_7, $spec_8, $spec_9, $spec_10, $info_1, $info_2, $info_3, $info_4, $info_5, $info_6, $info_7,$info_8,$info_9,$info_10, $_GET["id"]);
        $sql->execute();

        }else
        $sql = $con->prepare("UPDATE products SET category = ?, image = ?, productname = ?, price = ?, description = ?, details = ?, spec_1 = ?, spec_2 = ?, 
        spec_3 = ?, spec_4 = ?, spec_5 = ?, spec_6 = ?, spec_7 = ?, spec_8 = ?, spec_9 = ?, spec_10 = ?, info_1 = ?, info_2 = ?,
        info_3 = ?, info_4 = ?, info_5 = ?, info_6 = ?, info_7 = ?, info_8 = ?, info_9 = ?, info_10 = ?, link_1 = ? WHERE product_id = ?");
        $sql->bind_param("sssssssssssssssssssssssssssi", $category, $image, $productname, $price, $description, $details, $spec_1, $spec_2, $spec_3, $spec_4, $spec_5, $spec_6, $spec_7, $spec_8, $spec_9, $spec_10, $info_1, $info_2, $info_3, $info_4, $info_5, $info_6, $info_7,$info_8,$info_9,$info_10, $link_1, $_GET["id"]);
        if($sql->execute()) {
            echo "<div class='alert alert-success'>Successfully updated product</div>";
            }else{
                echo "<div class='alert alert-danger'>Error: There was an error while updating product info</div>";
                }
        }

        $id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
        $sql = $con->prepare("SELECT * FROM products WHERE product_id = ?");
        $sql->bind_param('i', $id);
        $sql->execute();
        $result = $sql->get_result();

        if($result->num_rows < 1){
        header('Location: index.php');
        exit;
        }
        $row = $result->fetch_assoc();
    ?>

    <div class="row">
    <div class="col-md-6 col-md-offset-3">
        <div class="box2">
            <h3><i class="glyphicon glyphicon-plus"></i>&nbsp;Modify Product</h3> 
            <form action="" method="POST" enctype="multipart/form-data">
                <input type="hidden" value="<?php echo $row['product_id']; ?>" name="productid">
                <label for="category">Category</label>
                <input type="text" id="category"  name="category" value="<?php echo $row['category']; ?>" class="form-control"><br>
                <label for="name">Image</label><br><br>
                <span><?php echo '<img src="Images/'. $row['image'], '" />'?></span><br><br>
                <input type="file"  name="image" id="image" value="<?php echo $row['image']; ?>"  class="form-control"><br>
                <label for="name">Name</label>
                <input type="text"  name="productname" id="name" value="<?php echo $row['productname']; ?>" class="form-control"><br>
                <label for="price">Price</label>
                <input type="text"  name="price" id="price" value="<?php echo $row['price']; ?>" class="form-control"><br>
                <label for="description">Description</label> 
                <input type="text"  name="description" id="description"  value="<?php echo $row['description']; ?>" class="form-control"><br>
                <h3><i class="glyphicon glyphicon-plus"></i>&nbsp;Modify Product Details</h3><br>
                <label class="heading" for="heading">Product Details</label><br>
                <textarea name="details" id="details" class="form-control ckeditor">
                <?php echo $row['details']; ?>
                </textarea>
                <br>
                <h3><i class="glyphicon glyphicon-plus"></i>&nbsp;Modify Specifications</h3><br>
                <label class="heading" for="heading">Heading</label>
                <input type="text" id="spec_1"  name="spec_1" value="<?php echo $row['spec_1']; ?>"class="form-control head_1"><br>
                <label class="information" for="information">Information</label>
                <input type="text" id="info_1"  name="info_1" value="<?php echo $row['info_1']; ?>" class="form-control info_1"><br>
                <input type="text" id="spec_2"  name="spec_2" value="<?php echo $row['spec_2']; ?>"class="form-control head_2"><br>
                <input type="text" id="info_2"  name="info_2" value="<?php echo $row['info_2']; ?>" class="form-control info_2"><br>
                <input type="text" id="spec_3"  name="spec_3" value="<?php echo $row['spec_3']; ?>"class="form-control head_3"><br>
                <input type="text" id="info_3"  name="info_3" value="<?php echo $row['info_3']; ?>" class="form-control info_3"><br>
                <input type="text" id="spec_4"  name="spec_4" value="<?php echo $row['spec_4']; ?>"class="form-control head_4"><br>
                <input type="text" id="info_4"  name="info_4" value="<?php echo $row['info_4']; ?>" class="form-control info_4"><br>
                <input type="text" id="spec_5"  name="spec_5" value="<?php echo $row['spec_5']; ?>"class="form-control head_5"><br>
                <input type="text" id="info_5"  name="info_5" value="<?php echo $row['info_5']; ?>" class="form-control info_5"><br>
                <input type="text" id="spec_6"  name="spec_6" value="<?php echo $row['spec_6']; ?>"class="form-control head_6"><br>
                <input type="text" id="info_6"  name="info_6" value="<?php echo $row['info_6']; ?>" class="form-control info_6"><br>
                <input type="text" id="spec_7"  name="spec_7" value="<?php echo $row['spec_7']; ?>"class="form-control head_7"><br>
                <input type="text" id="info_7"  name="info_7" value="<?php echo $row['info_7']; ?>" class="form-control info_7"><br>
                <input type="text" id="spec_8"  name="spec_8" value="<?php echo $row['spec_8']; ?>"class="form-control head_8"><br>
                <input type="text" id="info_8"  name="info_8" value="<?php echo $row['info_8']; ?>" class="form-control info_8"><br>
                <input type="text" id="spec_9"  name="spec_9" value="<?php echo $row['spec_9']; ?>"class="form-control head_9"><br>
                <input type="text" id="info_9"  name="info_9" value="<?php echo $row['info_9']; ?>" class="form-control info_9"><br>
                <input type="text" id="spec_10"  name="spec_10" value="<?php echo $row['spec_10']; ?>"class="form-control head_10"><br>
                <input type="text" id="info_10"  name="info_10" value="<?php echo $row['info_10']; ?>" class="form-control info_10"><br>
                <h3 class="links"><i class="glyphicon glyphicon-plus"></i>&nbsp;Add New Links</h3><br>
                <label class="links" for="links">Links</label><br><br>
                <span><?php echo $row['link_1']?></span>
                <input type="file"  name="link_1" id="link_1" value="<?php echo $row['link_1']; ?>"  class="form-control"><br>
                <br>
                <br>
                <br>
                <input type="submit" name="update" class="btn btn-success button2" value="Update">
            </form>
        </div>
    </div>
</div>
</div>
</body>
</html>

您的帮助将非常感谢和道歉,我仍然是新的和第一次尝试在积垢系统。谢谢您。

drkbr07n

drkbr07n1#

问题是你没有打开 { 在else行 61 所以:

}else
$sql = $con->prepare

收件人:

}else{
$sql = $con->prepare

相关问题