Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbsrvprg/slutprojekt/

admin.php
confirmSignIn.php
createadmin.php
logIn.php
signIn.php
start.php
startsida.php
style.css
tables.php
update.php

update.php

81 lines UTF-8 Windows (CRLF)
<?php 
  
/** @var PDO $dbconn */
  
include ("start.php");

  if (
$_COOKIE["type"] != "admin") {
    
header("location: startsida.php");
  }
?>

<?php 
  
// Om alla värden är satta, uppdatera kontot med de nya värdena
  
if (isset($_POST["playerid"]) && !empty($_POST["playerid"]) &&
  isset(
$_POST["username"]) && !empty($_POST["username"]) && 
  isset(
$_POST["password"]) && !empty($_POST["password"]) &&
  isset(
$_POST["mail"]) && !empty($_POST["mail"]) &&
  isset(
$_POST["type"]) && !empty($_POST["type"])) {
    
$id htmlspecialchars($_POST["playerid"]);
    
$user htmlspecialchars($_POST["username"]);
    
$pwd htmlspecialchars($_POST["password"]);
    
$mail htmlspecialchars($_POST["mail"]);
    
$type htmlspecialchars($_POST["type"]);

    try {    
        
$sql "UPDATE JassPlayers SET username=?, password=?, type=?, mail=? 
          WHERE playerid=?"
;
        
$stmt $dbconn->prepare($sql);
        
        
$data = array($user$pwd$type$mail$id);
        
$stmt->execute($data);
    }
    catch(
PDOException $e) {
      echo 
$sql "<br>" $e->getMessage();
    }
  }
?>

<?php 
  $id 
null;
  
$user null;
  
$pwd null;
  
$mail null;
  
$type null;

  if (isset(
$_GET["playerid"])) {
    try {
      
// Välj kontot med det inskickade id:t
      
$id $_GET["playerid"];
      
$sql "SELECT * FROM JassPlayers WHERE playerid=?";
      
$stmt $dbconn->prepare($sql);

      
$data = array($id);
      
$stmt->execute($data);

      
$res $stmt->fetch(PDO::FETCH_ASSOC);

      
// Spara kontots värden
      
$user $res["username"];
      
$pwd $res["password"];
      
$mail $res["mail"];
      
$type $res["type"];
    }
    catch(
PDOException $e) {
      echo 
$sql "<br>" $e->getMessage();
    }
  }
?>

  <!-- Skriv ut all kontoinformation i ett formulär där de kan ändras -->
  <form method="post">
    <table>    
      <tr><td>Användarnamn: </td><td><input type="text" name="username" value="<?= $user?>"><td></tr>
      <tr><td>Lösenord: </td><td><input type="text" name="password" value="<?= $pwd?>"></td></tr>
      <tr><td>E-mail: </td><td><input type="text" name="mail" value="<?= $mail?>"></td></tr>
      <tr><td>Typ: </td><td><input type="text" name="type" value="<?= $type?>"></td></tr>
    </table>

    <input type="hidden" name="playerid" value="<?= $id ?>">
    <input type="submit" value="Uppdatera">
  </form>
</body>
</html>