Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php include 'server.php';
- //fetch the record
- if (isset($_GET['edit'])) {
- $id = $_GET['edit'];
- $edit_state = true;
- $rec = mysqli_query($db, "SELECT * FROM users where id=$id");
- $record = mysqli_fetch_array($rec);
- $username = $record['username'];
- $password = $record['password'];
- $lastname = $record['lastname'];
- $firstname = $record['firstname'];
- $sample = "tangina";
- $sample2 = "gago";
- $sample3 = "okay";
- $id = $record['id'];
- }
- if (isset($_GET['edit1'])) {
- $id = $_GET['edit1'];
- $edit_state = true;
- $rec = mysqli_query($db, "SELECT * FROM users where id=$id");
- $record = mysqli_fetch_array($rec);
- $username = $record['username'];
- $password = $record['password'];
- $lastname = $record['lastname'];
- $firstname = $record['firstname'];
- $sample = "first";
- $sample2 = "second";
- $sample3 = "thrid";
- $id = $record['id'];
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Account Settings</title>
- <link rel="stylesheet" type="text/css" href="css/acc-style.css">
- </head>
- <body>
- <?php if (isset($_SESSION['msg'])): ?>
- <div class="msg">
- <?php
- echo $_SESSION['msg'];
- unset($_SESSION['msg']);
- ?>
- </div>
- <?php endif ?>
- <table>
- <thead>
- <tr>
- <th>Username</th>
- <th>Password</th>
- <th>Lastname</th>
- <th>Firstname</th>
- <th colspan="2">Action</th>
- </tr>
- </thead>
- <tbody>
- <?php while ($row = mysqli_fetch_array($results)) { ?>
- <tr>
- <td><?php echo $row['username']; ?></td>
- <td><?php echo $row['password']; ?></td>
- <td><?php echo $row['lastname']; ?></td>
- <td><?php echo $row['firstname']; ?></td>
- <td>
- <a href="index.php?edit=<?php echo $row['id']; ?>" class = "edit_btn" onclick="myFunction()">Edit</a>
- </td>
- <td>
- <a href="index.php?edit1=<?php echo $row['id']; ?>" class="delete_btn">Delete</a>
- </td>
- </tr>
- <?php } ?>
- </tbody>
- </table>
- <form method="post" action="server.php">
- <input type="hidden" name="text_id" value="<?php echo $id; ?>">
- <div class="input-group">
- <label>Username</label>
- <input type="text" name="text_username" value="<?php echo $sample; ?>" required>
- </div>
- <div class="input-group">
- <label>Password</label>
- <input type="text" name="text_password" value="<?php echo $sample2; ?>" required>
- </div>
- <div class="input-group">
- <label>Lastname</label>
- <input type="text" name="text_lastname" value="<?php echo $sample3; ?>" required>
- </div>
- <div class="input-group">
- <label>Firstname</label>
- <input type="text" name="text_firstname" value="<?php echo $sample; ?>" required>
- </div>
- <div class="input-group">
- <?php if ($edit_state == false): ?>
- <button type="submit" name="save" class="btn" onclick="myFunction()">Save</button>
- <?php else: ?>
- <button type="submit" name="update" class="btn">Update</button>
- <?php endif ?>
- </div>
- </form>
- <!--dashboard-->
- <div id="header">
- <div class="logo"><a href="#">Pacific Sky Beach Resort Admin Panel <span></span></a></div>
- </div>
- <div id="container">
- <div class="sidebar">
- <ul id="nav">
- <li><a href="dashboard.php">Dashboard</a></li>
- <li><a href="cms.php">CMS</a></li>
- <li><a class="selected" href="acc-settings.php">Account Settings</a></li>
- <li><a href="#">Reservation/Cancelation</a></li>
- <li><a href="login.php">Logout</a></li>
- </ul>
- </div>
- <script>
- function myFunction() {
- var txt;
- var r = confirm("Press a button!");
- if (r == true) {
- txt = if (isset($_POST['edit'])) {
- $username = $_POST['text_username'];
- $password = $_POST['text_password'];
- $lastname = $_POST['text_lastname'];
- $firstname = $_POST['text_firstname'];
- $sample = "tanginamo";
- $id = $_POST['text_id'];
- mysqli_query($db, "UPDATE users SET username = '$username', password = '$password', lastname = '$lastname', firstname = '$firstname' where id=$id");
- $_SESSION['msg'] = "Account Updated!";
- header('location: index.php');
- } else {
- txt = "You pressed Cancel!";
- }
- document.getElementById("demo").innerHTML = txt;
- }
- </script>
- </body>
- </html>
- <?php
- session_start();
- $username = "";
- $password = "";
- $lastname = "";
- $firstname = "";
- $sample = "";
- $sample2 = "";
- $sample3 = "";
- $id = 0;
- $edit_state = false;
- //connect to the database
- $db = mysqli_connect('localhost', 'root', '', 'login');
- //update
- if (isset($_POST['edit'])) {
- $username = $_POST['text_username'];
- $password = $_POST['text_password'];
- $lastname = $_POST['text_lastname'];
- $firstname = $_POST['text_firstname'];
- $sample = "tanginamo";
- $id = $_POST['text_id'];
- mysqli_query($db, "UPDATE users SET username = '$username', password = '$password', lastname = '$lastname', firstname = '$firstname' where id=$id");
- $_SESSION['msg'] = "Account Updated!";
- header('location: index.php');
- }
- //retrieve records
- $results = mysqli_query($db, "SELECT * FROM users");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement