Webbserverprogrammering 1

Show sourcecode

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

webbsrvprg/exercises/ovning9/2/

admin.php
deletetable.php
laggtill.php
skapatabell.php
skriverut.php
uppdatera.php
welcome.php

deletetable.php

89 lines ASCII Windows (CRLF)
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Delete</title>
</head>

<body>

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

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

echo 
$message;
/*
 // Fetch all rows ordered by the current ID
$rows = $pdo->query("SELECT * FROM kompisar ORDER BY idnummer")->fetchAll(PDO::FETCH_ASSOC);

// Update IDs sequentially
$new_idnummer = 1;
$stmt = $pdo->prepare("UPDATE your_table SET idnummer = :new_idnummer WHERE idnummer = :old_idnummer");
foreach ($rows as $row) {
    $stmt->execute(['new_idnummer' => $new_idnummer, 'old_idnummer' => $row['idnummer']]);
    $new_idnummer++;
}
*/

    
// Ouput table with all posts
/*** The SQL SELECT statement ***/
$sql "SELECT * FROM anvandaretabell";
$stmt $dbconn->prepare($sql);
// fetch width column names, create a table
$data = array();  
$stmt->execute($data);
$output "<table><caption>En ostylad tabell!</caption>";
while (
$res $stmt->fetch(PDO::FETCH_ASSOC)) {
    
$idx htmlentities($res['id']);
    
$first htmlentities($res['firstname']);
    
$last htmlentities($res['lastname']);
    
$anv htmlentities($res['anvandare']);
    
$passw htmlentities($res['passw']);
    
$typ htmlentities($res['typ']);
    
    
$output .= "<tr>".
        
"<td>$idx</td>".
        
"<td>$first</td>".
        
"<td>$last</td>".
        
"<td>$anv</td>".
        
"<td>$passw</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;
?>
  <a href="../ovn_sql2.php">Tillbaks till meny</a>
</body>
</html>