這裏我試圖通過模態彈出窗體將文本區域和隱藏字段的值傳遞給php。更新數據庫時缺少參數錯誤
我有一個隱藏字段,其中包含product ID
,文本區域包含一些文本。當我點擊提交按鈕時,它應該傳遞給PHP並在數據庫中更新。 當我填寫表格,然後點擊提交我收到錯誤
Notice: Undefined variable: prod_id
Warning: Missing argument 1 for updateProduct()
HTML
<div class="modal fade" id="rejectModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Are you sure to reject this product?</h4>
</div>
<div class="modal-body">
<h4>Why do you want to reject this product!</h4>
<form action="product-reject.php" method="get" role="form" enctype="multipart/form-data">
<?php
echo '<input type="hidden" class="form-control" name="product_id" id="user_role" value="'.$qs.'">';
echo '<textarea cols="43" rows="5" class="reject-textarea" name="reject_reason"></textarea>';
?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input type="submit" class="btn btn-primary" value="OK">
</div>
</form>
</div>
</div>
</div>
腓
<?php
require_once('configuration.php');
$product_id = $_GET['product_id'];
$reject_for = $_GET['reject_reason'];
if (isset($product_id,$reject_for)){
rejectProduct($product_id,$reject_for);
} else {
echo "Are you trying to do something nasty??";
}
function rejectProduct($product_id,$reject_for)
{
$conn = new mysqli(db_host, db_user, db_password, db_name);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO rejected_products(product_id,reason_to_reject) VALUES ($product_id,'$reject_for')";
$result = $conn->query($sql);
if ($conn->query($sql) === TRUE) {
updateProduct($prod_id);
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
}
function updateProduct($prod_id)
{
$conn = new mysqli(db_host, db_user, db_password, db_name);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE list SET product_publish_status = '2' WHERE product_id = '$prod_id'";
$result = $conn->query($sql);
if ($conn->query($sql) === TRUE) {
updateProduct();
header("Location: index.php");
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
}
?>
我怎樣才能解決這個問題?
是什麼'的UpdateProduct($ PROD_ID)'$ prod_id';'? – Lal
發現SQL注入 – Naruto
爲什麼要遞歸調用'updateProduct()'? – jeroen