Example #1
0
    //validation form data
    $id = $_POST['id'];
    $product = Product::showEditProduct($id);
    //We get a product that will edit
    $product_info = array();
    //an array of product characteristics
    while ($res = mysqli_fetch_assoc($product)) {
        $product_info[] = $res;
        //fill an array of product characteristics
    }
    echo json_encode($product_info);
    //response to Ajax (send product characteristics to JavaScript )
}
if (isset($_POST['edit_id'])) {
    //Conditions to EDIT product in Database
    $_POST = trimAll($_POST);
    //validation form data
    $_POST = htmlAll($_POST);
    //validation form data
    $edit_id = $_POST['edit_id'];
    $edit_code = $_POST['edit_code'];
    $edit_name = $_POST['edit_name'];
    $edit_price = $_POST['edit_price'];
    $product_edit = Product::editProduct($edit_id, $edit_code, $edit_name, $edit_price);
    //edit product in Database
    if ($product_edit == TRUE) {
        echo 'Product successfully edited';
    } else {
        echo 'Please try again';
    }
}