Webbserverprogrammering 1

Show sourcecode

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

ramverket/incl/

config.php
connect_db.php
db_handler.php
footer.php
header.php
ovn_incl1.php
ovn_incl2_end.php
ovn_incl2_start.php
ovn_incl3.php
ovn_incl4_end.php
ovn_incl4_start.php

db_handler.php

73 lines ASCII Windows (CRLF)
<?php 
  
function createTable($conn$table) {
     
$sql "CREATE TABLE $table (
      id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
      first_name VARCHAR(30) NOT NULL,
      last_name VARCHAR(30) NOT NULL,
      username VARCHAR(30) NOT NULL,
      password VARCHAR(30) NOT NULL,
      type VARCHAR(30) NOT NULL,
      mobile VARCHAR(50),
      email VARCHAR(50)
      )"
;

      
$stmt $conn->prepare($sql);
      
$stmt->execute();
    }

    function 
tableExists($conn$table) {
      
$sql "SHOW TABLES LIKE '$table'";
      
$stmt $conn->prepare($sql);
      
$stmt->execute();

      return 
$stmt->rowCount() > 0;
    }

    function 
getTableRow($conn$table$key$value) {
      
$sql "SELECT * FROM $table where $key = '$value'";
      
$stmt $conn->prepare($sql);
      
$stmt->execute();

      return 
$stmt;
    }

    function 
getAllTableRows($conn$table) {
      
$sql "SELECT * FROM $table";
      
$stmt $conn->prepare($sql);
      
$stmt->execute();

      return 
$stmt;
    }

    function 
insertTableRow($conn$table$first_name$last_name$mobile$email) {
      
$sql "INSERT INTO $table (first_name, last_name, mobile, email) VALUES (?, ?, ?, ?)";
      
$stmt $conn->prepare($sql);
      
$stmt->execute([$first_name$last_name$mobile$email]);
    }

    function 
deleteTableRow($conn$table$id) {
      
$sql "DELETE FROM $table WHERE id = ?";
      
$stmt $conn->prepare($sql);
      
$stmt->execute([$id]);
    }

    function 
deleteAllTableRows($conn$table) {
      
$sql "DELETE FROM $table";
      
$stmt $conn->prepare($sql);
      
$stmt->execute();
    }

    function 
updateTableRow($conn$table$id$first_name$last_name$mobile$email) {
      
$sql "UPDATE $table SET first_name = ?, last_name = ?, mobile = ?, email = ? WHERE id = ?";
      
$stmt $conn->prepare($sql);
      
$stmt->execute([$first_name$last_name$mobile$email$id]);
    }

    function 
login($conn$table$username$password) {
      
$sql "SELECT * FROM $table WHERE username = ? AND password = ?";
      
$stmt $conn->prepare($sql);
      
$stmt->execute([$username$password]);

      return 
$stmt->rowCount() > 0;
    }
?>