هل هذا الكود صحيح <script type="text/javascript">


function deleteShop() {
    const shopId = $('input[name="shop_id"]').val(); // get the shop id from the hidden input
    $.ajax({
        url: 'delete_shop.php',
        type: 'POST',
        data: {shop_id: shopId},
        success: function (response) {
            if (response === 'success') {
                Swal.fire('تم الحذف بنجاح!', 'تم حذف المتجر.', 'success');
                setTimeout(function () {
                    window.location.href = 'index.php'; // redirect to the main page
                }, 1500);
            } else {
                Swal.fire('خطأ!', 'حدث خطأ ما أثناء حذف المتجر.', 'error');
            }
        },
        error: function (err) {
            // handle the error here
            console.error(err);
            Swal.fire('خطأ!', 'حدث خطأ ما أثناء حذف المتجر.', 'error');
        }
    });
}


</script> ام يتم كتابته بطريقة اخري
Answer:
Copy Answer
هذا الكود صحيح ويمكن كتابته بهذه الطريقة.
Question:
في هذا الكود <?php
session_start();
if (isset($_SESSION['owner_email']) and isset($_SESSION['key'])) {

    include('db_connect.php');
    $status = $_SESSION['status'];
    $owner_id = $_SESSION['owner_id'];
    $email = $_SESSION['owner_email'];
    $result = mysqli_query($con, "SELECT * FROM owner WHERE owner_status=1 AND owner_email='$email'");

    if (mysqli_num_rows($result) == 1)
        echo " ";
    else
        header("location:index.php");
} else {
    header("location:index.php");

}


if ($_SERVER["REQUEST_METHOD"] == "GET") {
    $getid = $_GET['id'];


    if (!empty($getid)) {
        $query = mysqli_query($con, "SELECT * FROM shop WHERE shop_id='$getid'");
        $row = mysqli_fetch_assoc($query);
    }
}


if ($_SERVER["REQUEST_METHOD"] == "POST") {


    $shop_id = $_POST['shop_id'];
    $shop_name = $_POST['shop_name'];
    $shop_email = $_POST['shop_email'];
    $shop_contact = $_POST['shop_contact'];
    $shop_address = $_POST['shop_address'];
    $shop_status = $_POST['shop_status'];


    $currency_symbol = $_POST['currency_symbol'];


    $query = mysqli_query($con, "SELECT * FROM shop WHERE shop_id='$shop_id'");
    $row = mysqli_fetch_assoc($query);

    $sql = mysqli_query($con, "Update shop SET shop_name='$shop_name',shop_email='$shop_email',shop_contact='$shop_contact',shop_address='$shop_address',currency_symbol='$currency_symbol',shop_status='$shop_status' WHERE shop_id='$shop_id'");

    if ($sql) {
        echo '<script type="text/javascript">';
        echo 'setTimeout(function () { swal.fire("Successfully updated!","Done!","success");';
        echo '}, 500);</script>';

        echo '<script type="text/javascript">';
        echo "setTimeout(function () { window.open('shop_information.php','_self')";
        echo '}, 1500);</script>';

    } else {// display the error message
        echo '<script type="text/javascript">';
        echo 'setTimeout(function () { swal.fire("ERROR!","Something Wrong!","error");';
        echo '}, 500);</script>';


    }


}
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Update Shop</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <script src="plugins/jquery.min/jquery.min.js"></script>

    <!--Preloader-->
    <link rel="stylesheet" href="dist/css/preloader.css">
    <script src="dist/js/preloader.js"></script>

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
    <script src="plugins/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="plugins/sweetalert2/sweetalert2.min.css">
    <script src="plugins/sweetalert2/sweetalert2.min.js"></script>


    <!-- Font Awesome -->
    <link rel="stylesheet" href="plugins/fontawesome-free/css/all.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
    <!-- DataTables -->
    <link rel="stylesheet" href="plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
    <link rel="stylesheet" href="plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/adminlte.min.css">


    <script src="http://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.2/modernizr.js"></script>

    <!-- Bootstrap core CSS     -->
    <link href="plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>

    <!-- Google Font: Source Sans Pro -->
    <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
</head>
<body class="hold-transition sidebar-mini">
<div class="se-pre-con"></div>
<div class="wrapper">



    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <div class="container-fluid">
                <div class="row mb-2">
                    <div class="col-sm-6">
                        <h1>Shop Information</h1>

                    </div>

                </div>
            </div><!-- /.container-fluid -->
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-12">

                    <!-- /.card -->

                    <div class="card">
                        <div class="card-header">

                            <h3 class="card-title">Update shop information</h3>

                        </div>


                        <form role="form" id="quickForm" method="post" action="edit_shop.php">
                            <div class="card-body">

                                <div class="form-group">

                                    <input type="hidden" name="shop_id" class="form-control"
                                           id="exampleInputCustomerName"
                                           value="<?php echo $row['shop_id'] ?>">
                                </div>

                                <div class="form-group">
                                    <label for="exampleInputshopName">Shop Name</label>
                                    <input type="text" name="shop_name" class="form-control" id="exampleInputshopName"
                                           value="<?php echo $row['shop_name'] ?>">
                                </div>

                                <div class="form-group">
                                    <label for="exampleInputEmail1">Email address</label>
                                    <input type="email" name="shop_email" class="form-control" id="exampleInputEmail1"
                                           value="<?php echo $row['shop_email'] ?>">
                                </div>


                                <div class="form-group">
                                    <label for="exampleInputPhone">Phone Number</label>
                                    <input type="tel" name="shop_contact" class="form-control" id="exampleInputPhone"
                                           value="<?php echo $row['shop_contact'] ?>">
                                </div>

                                <div class="form-group">
                                    <label for="exampleInputAddress">Shop Address</label>
                                    <input type="text" name="shop_address" class="form-control" id="exampleInputAddress"
                                           value="<?php echo $row['shop_address'] ?>">
                                </div>


                                <div class="form-group">
                                    <label for="exampleInputCurrencySymbol">Currency Symbol</label>
                                    <input type="text" name="currency_symbol" class="form-control"
                                           id="exampleInputCurrencySymbol"
                                           value="<?php echo $row['currency_symbol'] ?>">
                                </div>


                                <div class="form-group">

                                    <div class="form-group">
                                        <label for="exampleShopStatus">Shop Status</label>
                                        <select class="form-control" name="shop_status" id="exampleShopStatus">
                                            <option value="<?php echo $row['shop_status'] ?>"><?php echo $row['shop_status'] ?></option>
                                            <option value="OPEN">OPEN</option>
                                            <option value="CLOSED">CLOSED</option>

                                        </select>


                                    </div>
                                </div>


                            </div>
                            <!-- /.card-body -->
                            <div class="card-footer">
                                <button type="submit" id="update_shop" class="btn btn-primary"><i
                                            class="fa fa-check-circle"></i> Update
                                    Shop Information
                                </button>
                                
                                <button type="button" id="delete_shop" class="btn btn-danger">
    <i class="fa fa-trash"></i> Delete Shop
</button>
                            </div>
                        </form>


                    </div>
                    <!-- /.card -->
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->
    </div>


    <!-- Control Sidebar -->
    <aside class="control-sidebar control-sidebar-dark">
        <!-- Control sidebar content goes here -->
    </aside>
    <!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->

<!-- jQuery -->
<script src="plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/adminlte.min.js"></script>


<!-- jQuery -->
<script src="plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- jquery-validation -->
<script src="plugins/jquery-validation/jquery.validate.min.js"></script>
<script src="plugins/jquery-validation/additional-methods.min.js"></script>

<script type="text/javascript">

    $(document).on('click', '#update_shop', function (e) {


        $('#quickForm').validate({
            rules: {

                shop_name: {
                    required: true
                },
                shop_email: {
                    required: true,
                    email: true,
                },
                shop_phone: {
                    required: true
                },
                shop_address: {
                    required: true
                },


            },
            messages: {
                shop_name: {
                    required: "Please enter shop name"
                },
                email: {
                    required: "Please enter a email address",
                    email: "Please enter a valid email address"
                },
                shop_phone: {
                    required: "Please enter shop phone number"
                },
                shop_address: {
                    required: "Please enter shop address"
                },

            },
            errorElement: 'span',
            errorPlacement: function (error, element) {
                error.addClass('invalid-feedback');
                element.closest('.form-group').append(error);
            },
            highlight: function (element, errorClass, validClass) {
                $(element).addClass('is-invalid');
            },
            unhighlight: function (element, errorClass, validClass) {
                $(element).removeClass('is-invalid');
            }
        });

    });


</script>


<script type="text/javascript">

    $(document).on('click', '#update_shop', function (e) {
        e.preventDefault();
        Swal.fire({
            title: 'Want to update ?',
            text: 'Are you sure?',
            icon: 'warning',
            type: 'warning',
            showCancelButton: true,
            confirmButtonText: 'Yes, Update it!',
            cancelButtonText: 'No'
        }).then((result) => {
            if (result.value) {

                $('#quickForm').submit();

            }
        })

    });
</script>

<script type="text/javascript">

$(document).on('click', '#delete_shop', function (e) {
    e.preventDefault();
    Swal.fire({
        title: 'هل تريد حذف المتجر؟',
        text: 'هل أنت متأكد؟',
        icon: 'warning',
        showCancelButton: true,
        confirmButtonText: 'نعم، احذفه!',
        cancelButtonText: 'لا'
    }).then((result) => {
        if (result.value) {
            // احذف المتجر هنا
            deleteShop();
        }
    })
});
</script>


<script type="text/javascript">


function deleteShop() {
    const shopId = $('input[name="shop_id"]').val(); // get the shop id from the hidden input
    $.ajax({
        url: 'delete_shop.php',
        type: 'POST',
        data: {shop_id: shopId},
        success: function (response) {
            if (response === 'success') {
                Swal.fire('تم الحذف بنجاح!', 'تم حذف المتجر.', 'success');
                setTimeout(function () {
                    window.location.href = 'index.php'; // redirect to the main page
                }, 1500);
            } else {
                Swal.fire('خطأ!', 'حدث خطأ ما أثناء حذف المتجر.', 'error');
            }
        },
        error: function (err) {
            // handle the error here
            console.error(err);
            Swal.fire('خطأ!', 'حدث خطأ ما أثناء حذف المتجر.', 'error');
        }
    });
}


</script>

</body>
</html>
 اين يتم اضافة <?php
if (isset($_POST['shop_id'])) {
    $shop_id = $_POST['shop_id'];
    
    include('db_connect.php');
    
    $query = "DELETE FROM shop WHERE shop_id='$shop_id'";
    $result = mysqli_query($con, $query);
    
    if ($result) {
        echo 'success';
    } else {
        echo 'error';
    }
} else {
    echo 'error';
}
?>