Webbserv1: Källkod
Webbserverprogrammering 1

Show sourcecode

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

webbsrvprg/exercises/databas/

admin.php
createtable.php
deletepost.php
deletetable.php
insertdefaultposts.php
insertpost.php
ovn_sqlintro1.php
ovn_sqlintro1_delete.php
ovn_sqlintro1_insert.php
ovn_sqlintro1_skapa.php
ovn_sqlintro1_skrivut.php
ovn_sqlintro1_update.php
ovn_sqlintro2.php
ovn_sqlintro2_delete.php
ovn_sqlintro2_insert.php
ovn_sqlintro2_login.php
ovn_sqlintro2_skapa.php
ovn_sqlintro2_skrivut.php
ovn_sqlintro2_update.php
ovn_sqlintro3.php
ovn_sqlintro3_default.php
ovn_sqlintro3_insert.php
ovn_sqlintro3_skapa.php
ovn_sqlintro3_skrivut.php
selectposts.php
updatepost.php
welcome.php

ovn_sqlintro2_delete.php

66 lines ASCII Windows (CRLF)
<!doctype html>
<html>

<body>

<?php
include ('../../dbconnection.php');
$message null;
$id null;

if (isset(
$_POST['id']) && !empty($_POST['id'])) {
    
$id $_POST['id'];
        
    try {    
        
$sql "DELETE FROM users WHERE id=?";
        
$stmt $dbconn->prepare($sql);
        
$data = array($id);
        
$stmt->execute($data);
            
        
$message .= "<br />Record deleted successfully.<br />";
    }
    catch(
PDOException $e)
        {
        
$message .= $sql "<br>" $e->getMessage();
    }
  } else {
    
$message .= "<br />";
  }

echo 
$message;
    
$sql "SELECT * FROM users";
$stmt $dbconn->prepare($sql);

$data = array();  
$stmt->execute($data);
$output "<table><caption>Users</caption>";
while (
$res $stmt->fetch(PDO::FETCH_ASSOC)) {
    
$idx htmlentities($res['id']);
    
$first htmlentities($res['firstname']);
    
$last htmlentities($res['lastname']);
    
$user htmlentities($res['user']);
    
$pass htmlentities($res['pass']);
    
$typ htmlentities($res['typ']);
    
    
$output .= "<tr>".
        
"<td>$idx</td>".
        
"<td>$first</td>".
        
"<td>$last</td>".
        
"<td>$user</td>".
        
"<td>$pass</td>".
        
"<td>$typ</td>".
        
"<td><form method='post' action=''>".
        
"<input type='hidden' name='id' value='$idx'>".
        
"<button type='submit'>Ta bort</button></form></td>".
    
"</tr>";
    
}
$output .= "</table>";
echo 
"$output";

$dbconn null;
?>

</body>
</html>