简体   繁体   English

MySQL PHP jQuery-行不更新吗?

[英]MySQL PHP jQuery - Row doesn't update?

I am writing a CMS and I'm stuck at updating existing products in the products table.... 我正在编写CMS,但仍无法更新products表中的现有产品。

The problem is that every value will receive the update besides the "text" and "stock" row... they go blank.... 问题在于,每个值除“文本”和“库存”行外还将接收更新...它们变为空白。

This is my code 这是我的代码

Form: 形成:

<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: 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: 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'>&times;</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'>&times;</a>
            <b>Oops, something went wrong..</b>
        </div>
        ";
}

}

更改jQuery文本字段值

var text = $("#newPostText").val();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM