[英]MySQL PHP jQuery - Row doesn't update?
我正在編寫CMS,但仍無法更新products表中的現有產品。
問題在於,每個值除“文本”和“庫存”行外還將接收更新...它們變為空白。
這是我的代碼
形成:
<form class="form-horizontal form-inline">
<div class="form-group">
<label class="control-label col-sm-3" for="title">Product:</label>
<input type="text" class="form-control" id="title" name="title" placeholder="Enter new title">
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="price">Price:</label>
<input type="text" class="form-control" id="price" name="price" placeholder="Enter new price">
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="stock">Stock:</label>
<input type="text" class="form-control" id="stock" name="stock" placeholder="Enter new stock">
</div>
<div class='form-group'>
<label class="control-label col-sm-3" for="text">Text:</label>
<textarea class='form-control' rows='5' id='newPostText' name='text' placeholder='Enter new text'></textarea>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="description">Description:</label>
<input type="text" class="form-control" id="description" name="description" placeholder="Enter new description">
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="brand">Brand:</label>
<input type="text" class="form-control" id="brand" name="brand" placeholder="Enter new brand">
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="keywords">Keywords:</label>
<input type="text" class="form-control" id="keywords" name="keywords" placeholder="Enter new keywords">
</div>
<a href="#" id="updateProductRecord" pid="<?php echo $pro_id; ?>"><button type="submit" id="submitUpdateProduct" class="btn btn-default">Submit</button></a>
</form>
jQuery的:
$("body").delegate("#updateProductRecord","click",function(event){
event.preventDefault();
var product_id = $(this).attr('pid');
updateProductRecord(product_id);
animatedLoading();
});
function updateProductRecord(product){
var title = $("#title").val();
var text = $("#text").val();
var summary = $("#description").val();
var keywords = $("#keywords").val();
var price = $("#price").val();
var stock = $("#stock").val();
var brand = $("#brand").val();
var product = product;
$.ajax({
url : "action.php",
method: "POST",
data : {updateProductRecord:1,pid:product,title:title,text:text,summary:summary,keywords:keywords,price:price,stock:stock,brand:brand},
success : function(data){
$(".row").append(data);
},
});
}
PHP:
if(isset($_POST['updateProductRecord'])) {
$product_id = $_POST['pid'];
$title = $_POST["title"];
$category = $_POST["brand"];
$text = $_POST['text'];
$summary = $_POST['summary'];
$keywords = $_POST['keywords'];
$price = $_POST['price'];
$stock = $_POST['stock'];
$date=date('d.m.y h:i:s');
$sql = "UPDATE products SET `title`='$title', `desc`='$summary', `price`='$price', `brand`='$category', `keywords`='$keywords', `stock`='$stock', `text`='$text' WHERE id='$product_id'";
$run_query = mysqli_query($connect,$sql);
if($run_query){
echo "
<div class='alert alert-success'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>
<b>Your post has been submitted.!</b>
</div>
";
}
else {
echo "
<div class='alert alert-warning'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>
<b>Oops, something went wrong..</b>
</div>
";
}
}
更改jQuery文本字段值
var text = $("#newPostText").val();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.