Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8" />
- <title>Edit user</title>
- <link rel="stylesheet" href="css/main.css">
- </head>
- <body>
- <?php
- require 'db/connect.php';
- $errors = array();
- if (isset($_GET['id'])){
- // Get id from the link
- $id = $_GET['id'];
- if (empty($id)){
- header ('Location: index.php');
- } else {
- // Get user information from ID
- if ($results = $db->query("SELECT * FROM `people` WHERE `id` = '{$id}'")){
- if ($results->num_rows){
- while ($row = $results->fetch_object()){
- $records = $row;
- }
- $results->free();
- }
- }
- }
- }
- // Edt user
- if (isset($_POST['edit'])){
- // Get informations from fields
- $first_name = trim($_POST['first_name']);
- $last_name = trim($_POST['last_name']);
- // Check fields
- if (empty($first_name) || empty($last_name)){
- $errors[] = '<br /><font color="red">Fields cannot be empty!</font>';
- } else {
- // Check length of first_name
- if (strlen($first_name) < 3 || strlen($first_name) > 15){
- $errors[] = '<br /><font color="red">First name needs to contain minimum 3 and maximum 15 chars!</font>';
- } else {
- // Check lenght of last_name
- if (strlen($last_name) < 3 || strlen($last_name) > 20){
- $errors[] = '<br /><font color="red">Last name needs to contain minimum 3 and maximum 20 chars!</font>';
- } else {
- // Update user
- $update = $db->prepare("UPDATE `people` SET `first_name` = ?, `last_name` = ?, `created` = NOW() WHERE `id` = '{$id}'");
- $update->bind_param('ss', $first_name, $last_name);
- if ($update->execute()){
- header('Location: index.php');
- die();
- } else {
- $errors[] = '<br /><font color="red">Currently you cannot update users. Admins are trying to fix this issue!</font>';
- }
- }
- }
- }
- }
- ?>
- <div class="content">
- <div class="edit_user">
- <?php
- if (count($records)){
- ?>
- <h3>Edit users: </h3>
- <form method="post" action="">
- <table>
- <tr>
- <td>First name:</td>
- <td><input type="text" name="first_name" value="<?php echo $records->first_name; ?>"></td>
- </tr>
- <tr>
- <td>Last name:</td>
- <td><input type="text" name="last_name" value="<?php echo $records->last_name; ?>"></td>
- </tr>
- <tr>
- <td></td>
- <td><input type="submit" name="edit" value="Edit"></td>
- </tr>
- </table>
- </form><!-- end form -->
- <?php
- } else {
- $errors[] = '<br /><font color="red">That user does not exist!</font>';
- }
- echo implode ($errors);
- ?>
- </div><!-- edit_user -->
- </div><!-- end content -->
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement