function findExerciseTypeById($typeid) { $typeid = trim_input($typeid); $sql = "select * from exercisetype where id=" . $typeid; $res = querySql($sql); if ($res) { return mysql_fetch_array($res, MYSQL_ASSOC); } return null; }
public function doedit() { if (isset($_POST["btnSubmit"])) { //============================== Purifier ============================== $this->load->helper('Validation'); $this->load->helper('HTMLPurifier'); $config = HTMLPurifier_Config::createDefault(); $purifier = new HTMLPurifier($config); // $clean_html = $purifier->purify($dirty_html); //su dung //============================== Purifier ============================== $update_data = array(); $war = array(); $loi = array(); $has_new_detail_image = false; $product_id = $_POST['product_id']; $page = isset($_POST['page']) && is_numeric($_POST['page']) ? $_POST['page'] : 1; $old_detail_image = $this->Product->get_detail_image($product_id); $old_avatar = $this->Product->get_avatar($product_id); $delete_detail_img = empty($_POST['delete_detail_img']) ? array() : $_POST['delete_detail_img']; if (count($_FILES['detail_img']['name']) > 0) { $imgs = $_FILES['detail_img']; $url = ''; $tmp_name_detail_img = array(); for ($i = 0; $i < count($_FILES['detail_img']['name']); $i++) { if ($_FILES['detail_img']['name'][$i] != '') { $tmp = new SplFileInfo($_FILES['detail_img']['name'][$i]); $type = $tmp->getExtension(); if (strtolower($type) != 'jpg' && strtolower($type) != 'gif' && strtolower($type) != 'png') { $war[] = "Dịnh dạng ảnh chi tiết sản phẩm không cho phép!"; $type = $tmp->getExtension(); } elseif ($_FILES['detail_img']['size'][$i] > 1024000) { $war[] = "Ảnh chi tiết sản phẩm phải nhỏ hơn 2MB"; } elseif (!isImage($_FILES['detail_img']['tmp_name'][$i])) { $war[] = "Ảnh chi tiết không phải là file ảnh!"; } else { $url = $url . '|' . htmlspecialchars(md5($_POST['product_name'])) . '-' . $i . time() . '.' . $type; $tmp_name_detail_img[] = $_FILES['detail_img']['tmp_name'][$i]; } } } if (trim($url, '|') != '') { $new_detail_image = trim($url, '|'); $update_data['detail_image'] = $old_detail_image . '|' . $new_detail_image; $update_data['detail_image'] = trim($update_data['detail_image'], '|'); $has_new_detail_image = true; } } if (!empty($delete_detail_img)) { if ($has_new_detail_image) { foreach ($delete_detail_img as $value) { $update_data['detail_image'] = str_replace($value . '|', '', $update_data['detail_image']); } } else { $update_data['detail_image'] = $old_detail_image . '|'; foreach ($delete_detail_img as $value) { $update_data['detail_image'] = str_replace($value . '|', '', $update_data['detail_image']); } } $update_data['detail_image'] = trim($update_data['detail_image'], '|'); } $update_data['product_name'] = trim_input($_POST["product_name"]); $update_data['category_id'] = $_POST["category_id"]; $update_data['des'] = $purifier->purify($_POST["des"]); $update_data['price'] = trim_input($_POST["price"]); $update_data['size'] = $purifier->purify($_POST["size"]); $update_data['substance'] = $purifier->purify($_POST["substance"]); //====================== Validate START ====================== if (!empty($_FILES['avatar']['name'])) { $avatar_name = $_FILES['avatar']['name']; $tmp = new SplFileInfo($avatar_name); $avatar_type = $tmp->getExtension(); if (strtolower($avatar_type) != 'jpg' && strtolower($avatar_type) != 'gif' && strtolower($avatar_type) != 'png') { $loi[] = "Định dạng ảnh đại diện sản phẩm không cho phép!"; } elseif (!isImage($_FILES['avatar']['tmp_name'])) { $loi[] = "Ảnh đại diện sản phẩm không phải là file ảnh!"; } elseif ($_FILES['avatar']['size'] > 2048000) { $loi[] = "Ảnh đại diện sản phẩm phải nhỏ hơn 2MB"; } else { $tmp_name_avatar = $_FILES['avatar']['tmp_name']; $update_data['image'] = md5($update_data['product_name']) . '-' . time() . '.' . $avatar_type; } } if (empty($_POST["product_name"])) { $loi[] = "Tên sản phẩm không được rỗng"; } elseif (strip_tags($_POST["product_name"]) == '') { $loi[] = "Tên sản phẩm không hợp lệ!"; } else { if (strlen($_POST["product_name"]) >= 4 && strlen($_POST["product_name"]) <= 100) { $update_data['product_name'] = $_POST["product_name"]; $update_data['product_name'] = trim($_POST["product_name"]); $update_data['product_name'] = strip_tags($_POST["product_name"]); $update_data['product_name'] = addslashes($update_data['product_name']); $product_name_exist = $this->Product->has_exist_product_name($update_data['product_name'], $product_id); if ($product_name_exist) { $loi[] = "Sản phẩm đã tồn tại"; } } else { $loi[] = "Tên sản phẩm phải dài hơn 4 và nhỏ hơn 100 kí tự!"; } } if (empty($update_data['category_id'])) { $loi[] = "Chưa chọn loại sản phẩm!"; } elseif (!is_numeric($update_data['category_id']) || !$this->Category->has_sub_category_exist_by_id($update_data['category_id'])) { $loi[] = "Loại sản phẩm không hợp lệ!"; } if (!empty($update_data['price'])) { if (!is_numeric($update_data['price'])) { $loi[] = "Giá phải là kiểu số!"; } } //====================== Validate END ====================== if (count($loi) > 0) { $alert_time = 20000; set_notice(FAILED_STATUS, $loi, $alert_time); $data['category'] = $this->Category->list_all_sub_category(); $redata['info'] = $this->Product->get_product_by_id($product_id); $redata['re_product_name'] = $_POST['product_name']; $redata['re_category_id'] = $_POST['category_id']; $redata['re_price'] = $_POST['price']; $redata['re_size'] = $_POST['size']; $redata['re_substance'] = $_POST['substance']; $redata['re_des'] = $_POST['des']; $redata['re_page'] = $page; $data['subView'] = '/product/edit_product_layout'; $data['title'] = 'Cập nhật sản phẩm'; $data['subData'] = $redata; $this->load->view('/main/main_layout', $data); } else { $rs = $this->Product->update($product_id, $update_data); // ============= Xoa anh chi tiet =================== if ($rs && !empty($delete_detail_img)) { foreach ($delete_detail_img as $value) { @unlink('public/img/detail_img/' . $value); } } // ============= Xoa anh chi tiet =================== // ============= Upload anh chi tiet =================== if ($rs && $has_new_detail_image) { $detail_image_name = explode('|', $new_detail_image); for ($i = 0; $i < count($detail_image_name); $i++) { $path = "public/img/detail_img/"; move_uploaded_file($tmp_name_detail_img[$i], $path . $detail_image_name[$i]); resizeImage($path . $detail_image_name[$i], $path . $detail_image_name[$i], 600, 600); } } // ============= Upload anh chi tiet =================== // ============= Upload anh avatar =================== if ($rs && isset($_FILES['avatar'])) { $path = "public/img/products/"; if (move_uploaded_file($tmp_name_avatar, $path . $update_data['image'])) { resizeImage($path . $update_data['image'], $path . $update_data['image'], 600, 600); @unlink('public/img/products/' . $old_avatar); } } // ============= Upload anh avatar =================== if ($rs) { if (!empty($war)) { $war['title'] = 'Cập nhật sản phẩm <span style="color:blue;"> ' . $update_data['product_name'] . '</span> thành công!'; $content = $war; $alert_time = 15000; set_notice(FAILED_STATUS, $content, $alert_time); header('location:' . base_url() . 'index.php/_admin/product'); } else { $mess = 'Cập nhật sản phẩm <span style="color:blue;"> ' . $update_data['product_name'] . '</span> thành công!'; set_notice(SUCCESS_STATUS, $mess); header('location:' . base_url() . 'index.php/_admin/product'); } } else { $mess = 'Có lỗi xảy ra cập nhật sản phẩm.'; set_notice(FAILED_STATUS, $mess); header('location:' . base_url() . 'index.php/_admin/product/add_product'); } } } }
require './../dao.php'; session_start(); if (!isset($_SESSION["user"])) { header("location:../index.php"); } $user = $_SESSION["user"]; $types = findExerciseTypes(); $res = false; $flag = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { $typeid = trim_input(filter_input(INPUT_POST, "typeid")); $count = trim_input(filter_input(INPUT_POST, "num")); $totaltime = trim_input(filter_input(INPUT_POST, "totaltime")); $date = trim_input(filter_input(INPUT_POST, "date")); $comment = trim_input(filter_input(INPUT_POST, "comment")); $res = addExercieRecord($typeid, $count, $totaltime, $date, $comment, $user["id"]); if ($res) { $flag = "记录添加成功"; } else { $flag = "记录添加失败"; } } ?> <html> <head> <meta charset="utf-8"> <link href="../css/bootstrap.min.css?v=3.4.0" rel="stylesheet"> <link href="../font-awesome/css/font-awesome.css?v=4.3.0" rel="stylesheet"> <link href="../css/animate.css" rel="stylesheet">
public function edit_super_category() { if (null != $this->input->post('edit_super_category_btn')) { $data_post = $this->input->post(); $this->load->helper('Validation'); $this->load->helper('HTMLPurifier'); $config = HTMLPurifier_Config::createDefault(); $purifier = new HTMLPurifier($config); $id = $data_post['super_category_id']; $data_update['super_categoryName'] = $purifier->purify($data_post['super_categoryName']); //========================= VALIDATION: START ======================= $error = array(); if (trim_input($data_update['super_categoryName']) == '') { $error = 'Tên loại danh mục không thể rỗng.'; } if ($this->Category->has_duplicate_super_category_name($data_update['super_categoryName'], $id)) { $error = 'Loại danh mục này đã tồn tại.'; } //========================= VALIDATION: END ========================= if (count($error) > 0) { // has error validate set_notice('status', FAILED_STATUS, $error); $data['re_super_category_name'] = $data_post['super_categoryName']; $data['re_super_category_id'] = $data_post['super_category_id']; $data['subView'] = '/category/edit_super_category_layout'; $data['title'] = "Cập nhật loại danh mục"; $data['subData'] = $data; $this->load->view('/main/main_layout', $data); } else { // not error validate $old_super_category_name = $this->Category->get_super_category_name_by_id($id); $new_super_category_name = $data_post['super_categoryName']; if ($this->Category->update_super_category($id, $data_update)) { if ($old_super_category_name != $new_super_category_name) { $content = 'Cập nhật loại danh mục <span style="color:blue;">' . $old_super_category_name . '</span> thành <span style="color:blue;">' . $new_super_category_name . '</span>'; } else { $content = 'Cập nhật loại danh mục <span style="color:blue;">' . $old_super_category_name . '</span> thành công.'; } set_notice('status', SUCCESS_STATUS, $content); header('location:' . base_url() . 'index.php/_admin/category/show_super_category'); } else { $content = 'Cập nhật loại danh mục <span style="color:blue;">' . $old_super_category_name . '</span> thất bại.'; set_notice('status', FAILED_STATUS, $content); header('location:' . base_url() . 'index.php/_admin/category/show_super_category'); } } } else { if (null !== $this->uri->segment(4) && is_numeric($this->uri->segment(4)) && $this->Category->has_super_category_exist_by_id($this->uri->segment(4))) { $super_category_id = $this->uri->segment(4); $data['super_category_info'] = $this->Category->get_super_category_info($super_category_id); $data['subView'] = '/category/edit_super_category_layout'; $data['title'] = "Cập nhật loại danh mục"; $data['subData'] = $data; $this->load->view('/main/main_layout', $data); } else { $data['pre_page'] = base_url() . 'index.php/_admin/category/show_super_category'; $this->load->view('/error/404_layout', $data); } } }
public function edit_account() { if (null != $this->input->post('edit_account_btn')) { $data_post = $this->input->post(); $this->load->helper('Validation'); $this->load->helper('HTMLPurifier'); $config = HTMLPurifier_Config::createDefault(); $purifier = new HTMLPurifier($config); //====================== Validate ====================== $error = array(); if (empty($_POST["username"])) { $error[] = "Username không được rỗng"; } else { if ((preg_match('/^[A-Za-z0-9_\\.]{4,30}$/', $_POST["username"], $maches) || preg_match('/^[A-Za-z0-9_\\.]{4,30}$/', $_POST["username"], $maches)) && (strlen($_POST["username"]) >= 4 && strlen($_POST["username"]) <= 30)) { $username = $_POST["username"]; $username = trim_input(trim($_POST["username"])); $username_exist = $this->Account->check_username_exist($username, $data_post['id']); if ($username_exist) { $error[] = "Username đã tồn tại"; } } else { $error[] = "Username gồm kí tự a-Z và có độ dài 4 - 30"; } } $regex = "/^[a-zA-Z0-9]+@[a-zA-Z0-9]+\\.[a-zA-Z]+\$/"; if (empty($_POST["email"])) { $error[] = "Email không được rỗng!"; } elseif (preg_match($regex, $_POST["email"], $maches)) { $insert_data['email'] = $_POST["email"]; } else { $error[] = "Email không hợp lệ!"; } if ($_POST['password'] != '' && strlen($_POST['password']) < 4) { $error[] = "Password phải nhiều hơn hoặc bằng 4 kí tự!"; } if ($data_post['password'] != '') { if (strlen($_POST['password']) < 4 || strlen($_POST['password']) > 32) { $error[] = "Password từ 4 đến 32 kí tự!"; } else { $data_update['password'] = md5($data_post['password']); } } if (!empty($_FILES['avatar']['name'])) { $avatar_name = $_FILES['avatar']['name']; $tmp = new SplFileInfo($avatar_name); $avatar_type = $tmp->getExtension(); if (strtolower($avatar_type) != 'jpg' && strtolower($avatar_type) != 'gif' && strtolower($avatar_type) != 'png') { $error[] = "Định dạng ảnh đại diện sản phẩm không cho phép!"; } elseif (!isImage($_FILES['avatar']['tmp_name'])) { $error[] = "Ảnh đại diện sản phẩm không phải là file ảnh!"; } elseif ($_FILES['avatar']['size'] > 2048000) { $error[] = "Ảnh đại diện sản phẩm phải nhỏ hơn 2MB"; } else { $tmp_name_avatar = $_FILES['avatar']['tmp_name']; $data_update['avatar'] = md5($_POST["username"]) . '-' . time() . '.' . $avatar_type; } } //====================== Validate ====================== if (count($error) > 0) { $redata['re_id'] = $_POST['id']; $redata['re_username'] = $_POST['username']; $redata['re_email'] = $_POST['email']; $redata['avatar'] = $this->Account->get_avatar_by_id($_POST['id']); $alert_time = 20000; set_notice('status', FAILED_STATUS, $error, $alert_time); $data['subData'] = $redata; $data['title'] = "Cập nhật tài khoản"; $data['subView'] = '/account/edit_account_layout'; $this->load->view('/main/main_layout', $data); } else { $id = $data_post['id']; $data_update['username'] = $purifier->purify($data_post['username']); $data_update['email'] = $data_post['email']; $old_avatar = $this->Account->get_avatar_by_id($id); $rs = $this->Account->update($id, $data_update); if (rs) { // ============= Upload anh avatar =================== if ($rs && isset($_FILES['avatar'])) { $path = "public/img/avatar/"; if (move_uploaded_file($tmp_name_avatar, $path . $data_update['avatar'])) { resizeImage($path . $data_update['avatar'], $path . $data_update['avatar'], 600, 600); @unlink($path . $old_avatar); } } // ============= Upload anh avatar =================== $this->load->model('Login_model', 'Login'); $user = $this->Login->getInfo($username); $_SESSION['user'] = $user; $content = 'Cập nhật tài khoản thành công.'; set_notice('status', SUCCESS_STATUS, $content); header('location:' . base_url() . 'index.php/_admin/order/show_order'); } else { $content = 'Cập nhật tài khoản thất bại.'; set_notice('status', FAILED_STATUS, $content); header('location:' . base_url() . 'index.php/_admin/order/show_order'); } } } else { if (null !== $this->uri->segment(4) && is_numeric($this->uri->segment(4)) && $this->Account->has_account_exist_by_id($this->uri->segment(4))) { $account_id = $this->uri->segment(4); $data['account_info'] = $this->Account->get_account_info($account_id); $data['subView'] = '/account/edit_account_layout'; $data['title'] = "Cập nhật tài khoản"; $data['subData'] = $data; $this->load->view('/main/main_layout', $data); } else { $data['pre_page'] = base_url() . 'index.php/_admin/acticle/show_account'; $this->load->view('/error/404_layout', $data); } } }
public function do_order() { date_default_timezone_set("Asia/Ho_Chi_Minh"); $this->load->model('Order_model', 'Order'); if (isset($_POST['phone'])) { $this->load->helper('validation'); $customer_name = trim_input($_POST['customer_name']); $phone = trim_input($_POST['phone']); $arr_product_id = (array) $_POST['product_id']; $arr_order_qty = (array) $_POST['order_qty']; $error = array(); //====================== VALIDATION: START ==================== if ($customer_name == '') { $error[] = 'Tên khách hàng không được để trống.'; } $regex = "/^[0-9]{9,11}\$/"; if ($phone == '') { $error[] = "Số điện thoại không được rỗng."; } elseif (!preg_match($regex, $phone, $maches)) { $error[] = "Số điện thoại không đúng."; } if (empty($arr_product_id)) { $error[] = "Không có có sản phẩm nào trong đơn hàng."; } else { foreach ($arr_product_id as $key => $value) { if (!$this->Product->check_product_exist($value)) { $error[] = 'Sản phẩm có mã <span style="color:red;">' . $value . '</span> không có trong hệ thống.'; } else { if ($arr_order_qty[$key] <= 0) { $product_name = $this->Product->get_product_name_by_id($arr_product_id[$key]); $error[] = 'Số lượng sản phẩm <span style="color:red;">' . $product_name . '</span> không thể bằng ' . '<span style="color:red;">' . $arr_order_qty[$key] . '</span>'; } } } } //====================== VALIDATION: END ====================== if (count($error) > 0) { set_notice('order', FAILED_STATUS, $error); header("location:" . base_url() . "index.php/site/cart/view_order"); } else { $now = new DateTime(date('Y-m-d H:i:s')); $data_insert['order_datetime'] = $now->format('Y-m-d H:i:s'); $data_insert['product_id_and_qty'] = ''; for ($i = 0; $i < count($arr_product_id); $i++) { $data_insert['product_id_and_qty'] .= $arr_product_id[$i] . '-' . $arr_order_qty[$i] . '|'; } $data_insert['product_id_and_qty'] = trim($data_insert['product_id_and_qty'], '|'); $data_insert['customer_name'] = $customer_name; $data_insert['phone'] = $phone; if ($this->Order->insert($data_insert)) { $this->cart->destroy(); //================ SEND MAIL TO ADMIN: START ================ $this->load->model('Account_model', 'Account'); $this->load->helper('mymail'); $arr_to_mail = $this->Account->get_list_email_admin(); if (!empty($arr_to_mail)) { $date_time_order = date('d/m/Y') . ' - ' . date("h:i:sa"); $subject = 'ĐƠN ĐẶT HÀNG MỚI (' . $date_time_order . ')'; $message = 'Có đơn đặt hàng mới từ:' . '<br>Khách hàng: ' . $customer_name . '<br>Số điện thoại: ' . $phone . '<br><br>'; $message .= '<html><body>'; $message .= '<table rules="all" style="min-width:300px; border-color: #666;" cellpadding="10">'; $message .= "<tr style='background: #eee;'><td><strong>Tên sản phẩm:</strong> </td><td>Số lượng</td></tr>"; foreach ($arr_product_id as $key => $value) { $message .= "<tr><td><strong>" . $this->Product->get_product_name_by_id($arr_product_id[$key]) . "</strong> </td><td>" . $arr_order_qty[$key] . "</td></tr>"; } $message .= "</table>"; $message .= "</body></html>"; send_mail($arr_to_mail, $subject, $message); } //================ SEND MAIL TO ADMIN: START ================ $content = '<div style="color: rgb(129, 127, 123); font-size: 16px;">' . 'Khách hàng: <span style="color:rgb(0, 165, 255);">' . $customer_name . '</span>' . '<br> Số điện thoại: <span style="color:rgb(0, 165, 255);">' . $phone . '</span>' . '<br><span style="color:rgb(129, 127, 123);"> Chúng tôi sẽ liên lạc lại cho quý khách trong thời gian sớm nhất!</span>' . '</div>'; set_notice('order', SUCCESS_STATUS, $content); header("location:" . base_url()); } else { header("location:" . base_url() . "index.php/site/cart/view_order"); $content = 'Có lỗi trong quá trình đặt hàng. <br> Vui lòng làm lại thực hiện lại!'; set_notice('order', FAILED_STATUS, $content); } } } else { header("location:" . base_url()); } }
<?php session_start(); require 'dao.php'; $username_error = $password_error = $repassword_error = $nicname_error = $captcha_error = $nicname = $error = null; $username = $password = $repassword = $nicname = $captcha = $msg = null; if ($_SERVER["REQUEST_METHOD"] == "POST") { $username = trim_input(filter_input(INPUT_POST, "username", FILTER_DEFAULT)); $nicname = trim_input(filter_input(INPUT_POST, "nicname", FILTER_DEFAULT)); $password = trim_input(filter_input(INPUT_POST, "password", FILTER_DEFAULT)); $repassword = trim_input(filter_input(INPUT_POST, "repassword", FILTER_DEFAULT)); $captcha = trim_input(filter_input(INPUT_POST, "Captcha", FILTER_DEFAULT)); $flag = true; if (is_null($username)) { $username_error = "用户名不能为空"; $flag = false; } else { if (mysql_num_rows(findUserByUsername($username)) > 0) { $username_error = "用户名已存在"; $flag = false; } } if (is_null($password)) { $password_error = "密码不能为空"; $flag = false; } else { if ($password != $repassword) { $repassword_error = "密码不一致"; $flag = false; } }
<?php require './../dao.php'; session_start(); if (!isset($_SESSION["user"])) { header("location:../index.php"); } $user = $_SESSION["user"]; $res = false; $flag = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { $title = trim_input(filter_input(INPUT_POST, "title")); $content = trim_input(filter_input(INPUT_POST, "plancontent")); $res = addExecisePlan($user["id"], $title, $content); if ($res) { $flag = "记录添加成功"; } else { $flag = "记录添加失败"; } } ?> <html> <head> <meta charset="utf-8"> <link href="../css/bootstrap.min.css?v=3.4.0" rel="stylesheet"> <link href="../font-awesome/css/font-awesome.css?v=4.3.0" rel="stylesheet"> <link href="../css/animate.css" rel="stylesheet"> <link href="../css/plugins/toastr/toastr.min.css" rel="stylesheet">
<?php require './../dao.php'; $method = trim_input(filter_input(INPUT_POST, "method")); switch ($method) { case "delExercisePlan": $planid = trim_input(filter_input(INPUT_POST, "planid")); delExercisePlanService($planid); break; default: break; } function delExercisePlanService($planid) { $res = delExercisePlan($planid); if ($res) { echo 'true'; } else { echo 'false'; } }
<?php require 'dao.php'; session_start(); if (isset($_SESSION["user"]) && $_SESSION["user"] != null) { header("location:userindex.php"); } $checkcode = null; if (isset($_SESSION['Checknum'])) { $checkcode = $_SESSION['Checknum']; } $username_error = $password_error = $captcha_error = null; $flag = true; $password = trim_input(filter_input(INPUT_POST, "password")); $username = trim_input(filter_input(INPUT_POST, "username")); $captcha = trim_input(filter_input(INPUT_POST, "Captcha")); if ($_SERVER["REQUEST_METHOD"] == "POST") { if (is_null($username)) { $username_error = "用户名不能为空"; $flag = false; } if (is_null($password)) { $password_error = "密码不能为空"; $flag = false; } if (is_null($captcha) || $checkcode != strtolower($captcha)) { $captcha_error = "验证码输入有误"; $flag = false; } if ($flag) { if (checkLogin($username, md5($password))) {
if (isset($_POST["member_name"])) { if ($stmt = $mysqli->prepare("UPDATE belongs_to SET authorized=1 WHERE group_id=? AND username=?")) { $member_name = trim_input($_POST["member_name"]); $stmt->bind_param("is", $_SESSION["group_id"], $member_name); $stmt->execute(); $stmt->close(); echo "The user has been authorized<br/>\n\n\t\t\t\tYou will be redirected in 5 seconds or click <a href=\"index.php\">here</a>.\n"; header("refresh: 5; index.php"); } } else { echo "An error has occurred"; } } else { // GET; display form if (isset($_GET["group_id"]) && ($stmt = $mysqli->prepare("SELECT username FROM belongs_to WHERE authorized = 0 AND group_id = ?"))) { $group_id = trim_input($_GET["group_id"]); $stmt->bind_param("i", $group_id); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($member_name); if ($stmt->num_rows > 0) { echo "<form action=\"authorize_user.php\" method=\"POST\">Choose the user to authorize<br/>\n\n\t\t\t\t<select name=\"member_name\">"; while ($stmt->fetch()) { echo "<option value=\"{$member_name}\">{$member_name}</option>\n"; } echo "</select>\n<input type=\"submit\" value=\"Authorize user\">"; // store group id in session, do not store using form since user may change it manually $_SESSION["group_id"] = $group_id; } else { echo "There are no users to authorize<br/>\n\n\t\t\t\tYou will be redirected in 5 seconds or click <a href=\"index.php\">here</a>.\n"; header("refresh: 5; index.php");