array("regexp"=>"/^[a-zA-Z\s]+$/")))){ $request_by_err = "Please enter a valid name."; } else{ $request_by = $input_request_by; } $input_reason = trim($_POST["Reason"]); $reason = $input_reason; $input_remail = trim($_POST["remail"]); $remail = $input_remail; // Check input errors before inserting in database if(empty($sysID_err) && empty($location_err) && empty($requestype_err) && empty($request_by_err)&& empty($remail_err) && empty($reason_err)){ // Prepare an update statement $sql = "UPDATE tickets SET sysID=?,location=?,requestype=?,rusername=?, remail=?, reason=? WHERE id=?"; if($stmt = mysqli_prepare($link, $sql)){ // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "ssssssi", $param_sysID, $param_location, $param_requestype, $param_requestby, $param_remail, $param_reason, $param_id); // Set parameters $param_sysID = $sysID; $param_location = $location; $param_requestype = $requestype; $param_requestby = $request_by; $param_remail = $remail; $param_reason = $reason; $param_id = $id; // Attempt to execute the prepared statement if(mysqli_stmt_execute($stmt)){ // Records updated successfully. Redirect to landing page header("location: tickets.php"); exit(); } else{ echo "Something went wrong. Please try again later."; } } // Close statement mysqli_stmt_close($stmt); } // Close connection mysqli_close($link); } else{ // Check existence of id parameter before processing further if(isset($_GET["id"]) && !empty(trim($_GET["id"]))){ // Get URL parameter $id = trim($_GET["id"]); // Prepare a select statement $sql = "SELECT * FROM tickets WHERE id = ?"; if($stmt = mysqli_prepare($link, $sql)){ // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "i", $param_id); // Set parameters $param_id = $id; // Attempt to execute the prepared statement if(mysqli_stmt_execute($stmt)){ $result = mysqli_stmt_get_result($stmt); if(mysqli_num_rows($result) == 1){ /* Fetch result row as an associative array. Since the result set contains only one row, we don't need to use while loop */ $row = mysqli_fetch_array($result, MYSQLI_ASSOC); // Retrieve individual field value $sysID = $row["sysID"]; $location = $row["location"]; $requestype = $row["requestype"]; $request_by = $row["rusername"]; $remail = $row["remail"]; $reason = $row["reason"]; $id = $row['id']; } else{ // URL doesn't contain valid id. Redirect to error page header("location: error.php"); exit(); } } else{ echo "Oops! Something went wrong. Please try again later."; } } // Close statement mysqli_stmt_close($stmt); // Close connection mysqli_close($link); } else{ // URL doesn't contain id parameter. Redirect to error page header("location: error.php"); exit(); } } ?> SYSDesk - Edit ticket #<?php echo $id; ?>

Ticket ID: