Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (isset($_GET['id'])) {
- include "db_conn.php";
- function validate($data){
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- return $data;
- }
- $id = validate($_GET['id']);
- $sql = "SELECT * FROM users WHERE id=$id";
- $result = mysqli_query($conn, $sql);
- if (mysqli_num_rows($result) > 0) {
- $row = mysqli_fetch_assoc($result);
- }else {
- header("Location: read.php");
- }
- }else if(isset($_POST['update'])) {
- include "../db_conn.php";
- function validate($data){
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- return $data;
- }
- $customer_name = validate($_POST['customer_name']);
- $customer_email = validate($_POST['customer_email']);
- $customer_mobile = validate($_POST['customer_mobile']);
- $poNum = validate($_POST['poNum']);
- $site_name = validate($_POST['site_name']);
- $street1 = validate($_POST['street1']);
- $id = validate($_POST['id']);
- if (empty($customer_name)) {
- header("Location: ../update.php?id=$id&error=Name is required");
- }else if (empty($customer_email)) {
- header("Location: ../update.php?id=$id&error=Email is required");
- }else if (empty($customer_mobile)) {
- header("Location: ../update.php?id=$id&error=Mobile is required");
- }else if (empty($poNum)) {
- header("Location: ../update.php?id=$id&error=PO Number is required");
- }else if (empty($site_name)) {
- header("Location: ../update.php?id=$id&error=Site Name is required");
- }else if (empty($street1)) {
- header("Location: ../update.php?id=$id&error=Address is required");
- }else {
- $sql = "UPDATE users
- SET customer_name='$customer_name', customer_email='$customer_email',
- customer_mobile='$customer_mobile', poNum='$poNum',
- site_name='$site_name', street1='$street1'
- WHERE id=$id ";
- $result = mysqli_query($conn, $sql);
- if ($result) {
- header("Location: ../read.php?success=Successfully Updated");
- }else {
- header("Location: ../update.php?id=$id&error=Unknown error occurred&$user_data");
- }
- }
- }else{
- header("Location: read.php");
- }
Advertisement
Add Comment
Please, Sign In to add comment