<?php
require_once('head-start.php');
require_once('connect.php'); ?>
<div class="page">
<div class="container">
<h1>Изменяем запись</h1>
<?php $id = $_GET['order_id'];
$sql = mysqli_query($connect, "SELECT * FROM orders WHERE order_id = '$id'");
$row = mysqli_fetch_assoc($sql);
if(isset($_POST['change'])) {
$order_name = $_POST['order_name'];
$order_description = $_POST['order_desc'];
$order_price = $_POST['order_price'];
$user_id = $_POST['user_id'];
$order_date = $_POST['order_date'];
$change_sql = mysqli_query($connect, "UPDATE orders SET order_name='$order_name', order_description='$order_description', order_price='$order_price', user_id='$user_id', order_date='$order_date' WHERE order_id='$id'");
}
if($change_sql) {
echo '1';
} else {
echo mysqli_error($connect);
}
?>
<form action="edit.php?order_id=<?php echo $id; ?>" method="post">
<input type="text" value="<?php echo $row['order_name']; ?>" name="order_name" placeholder="Заголовок">
<textarea name="order_desc" id="" cols="30" rows="10"><?php echo $row['order_description']; ?></textarea>
<input type="text" value="<?php echo $row['order_price']; ?>" name="order_price" placeholder="Цена">
<input type="text" value="<?php echo $row['user_id']; ?>" name="user_id" placeholder="Исполнитель">
<input type="text" value="<?php echo $row['order_date']; ?>" name="order_date" placeholder="Дата">
<input type="submit" name="change" value="Отправить">
</form>
</div>
</div>
<?php require_once('head-end.php'); ?>
$(document).ready(function(){
$("form").submit(function(e){
e.preventDefault();
let order_name = $('input[name="order_name"]').val();
let order_desc = $('textarea[name="order_desc"]').val();
let order_price = $('input[name="order_price"]').val();
let user_id = $('input[name="user_id"]').val();
let order_date = $('input[name="order_date"]').val();
$.ajax({
type: "POST",
url: "edit.php",
dataType: "html",
data: {
order_name: order_name,
order_description: order_desc,
order_price: order_price,
user_id: user_id,
order_date: order_date
},
success: function(data) {
alert(data);
}
});
});
});
action="edit.php?order_id=<?php echo $id; ?>"
url: "edit.php",
<input type="hidden" class="order-id" data-order-id="<?php echo $id; ?>">
$("form").submit(function(e){
e.preventDefault();
var id = $('.order-id').data('order-id');
let order_name = $('input[name="order_name"]').val();
let order_desc = $('textarea[name="order_desc"]').val();
let order_price = $('input[name="order_price"]').val();
let user_id = $('input[name="user_id"]').val();
let order_date = $('input[name="order_date"]').val();
$.ajax({
type: "POST",
url: `edit.php?order_id=${id}`,
dataType: "html",
data: {
order_name: order_name,
order_description: order_desc,
order_price: order_price,
user_id: user_id,
order_date: order_date,
change: true
},
success: function(data) {
alert(data);
}
});
});
});