Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // including the database connection file
- include("config.php");
- session_start();
- if($_SESSION){
- if($_SESSION["rank"] == 2){
- if(isset($_POST['update']))
- {
- $id = $_POST['id'];
- $username=$_POST['username'];
- $email=$_POST['email'];
- $password=$_POST['password'];
- $rank=$_POST['rank'];
- // checking empty fields
- if(empty($username) || empty($email) || empty($password) || empty($rank)) {
- if(empty($username)) {
- echo "<font color='red'>username field is empty.</font><br/>";
- }
- if(empty($email)) {
- echo "<font color='red'>email field is empty.</font><br/>";
- }
- if(empty($password)) {
- echo "<font color='red'>password field is empty.</font><br/>";
- }
- if(empty($rank)) {
- echo "<font color='red'>rank field is empty.</font><br/>";
- }
- } else {
- //updating the table
- $sql = "UPDATE users SET username=:username, email=:email, password=:password, rank=:rank WHERE id=:id";
- $query = $db->prepare($sql);
- $query->bindparam(':id', $id);
- $query->bindparam(':username', $username);
- $query->bindparam(':email', $email);
- $query->bindparam(':password', $password);
- $query->bindparam(':rank', $rank);
- $query->execute();
- // Alternative to above bindparam and execute
- // $query->execute(array(':id' => $id, ':name' => $name, ':email' => $email, ':age' => $age));
- //redirectig to the display page. In our case, it is admin.php
- header("Location: admin.php");
- }
- }
- //getting id from url
- $id = $_POST['id'];
- //selecting data associated with this particular id
- $sql = "SELECT * FROM users WHERE id=:id";
- $query = $db->prepare($sql);
- $query->execute(array(':id' => $id));
- while($row = $query->fetch(PDO::FETCH_ASSOC))
- {
- $username = $row['username'];
- $email = $row['email'];
- $password = $row['password'];
- $rank = $rank['rank'];
- }
- }
- else{
- echo "alleen voor admins beschikbaar.";
- }
- }
- else{
- echo "deze webpagina is niet beschikbaar.";
- }
- ?>
- <html>
- <head>
- <title>Edit Data</title>
- </head>
- <body>
- <a href="admin.php">Home</a>
- <br/><br/>
- <form name="form1" method="post" action="edituser.php">
- <table border="0">
- <tr>
- <td>Name</td>
- <td><input type="text" name="username" value="<?php echo $username;?>"></td>
- </tr>
- <tr>
- <td>email</td>
- <td><input type="text" name="email" value="<?php echo $email;?>"></td>
- </tr>
- <tr>
- <td>password</td>
- <td><input type="text" name="password" value="<?php echo $password;?>"></td>
- </tr>
- <tr>
- <td>rank</td>
- <td><input type="text" name="rank" value="<?php echo $rank;?>"></td>
- </tr>
- <tr>
- <td><input type="hidden" name="id" value=<?php echo $_POST['id'];?>></td>
- <td><input type="submit" name="update" value="Update"></td>
- </tr>
- </table>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement