Bind_param 警告变量数和参数不匹配
Bind_param warning number of variables and parameters don't match
当我去编辑图像以外的任何东西时 link 我得到这个错误“”,尽管它仍然更新项目并将其作为新的更新信息显示在我的产品列表中。参数和变量匹配,我已经计算了很多次,我开始认为它在代码中有其他东西。
enter image description here
enter image description here
这是我的编辑页面代码:
<?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> 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> 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> 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> 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>
非常感谢您的帮助和道歉我还是新手,第一次尝试 crud 系统。
谢谢。
问题是你没有在其他行 61
打开 {
所以:
}else
$sql = $con->prepare
至:
}else{
$sql = $con->prepare
当我去编辑图像以外的任何东西时 link 我得到这个错误“”,尽管它仍然更新项目并将其作为新的更新信息显示在我的产品列表中。参数和变量匹配,我已经计算了很多次,我开始认为它在代码中有其他东西。
enter image description here
enter image description here
这是我的编辑页面代码:
<?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> 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> 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> 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> 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>
非常感谢您的帮助和道歉我还是新手,第一次尝试 crud 系统。 谢谢。
问题是你没有在其他行 61
打开 {
所以:
}else
$sql = $con->prepare
至:
}else{
$sql = $con->prepare