Webbserverprogrammering 1

Show sourcecode

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

webbserverprogrammering/

assets/
comments.php
database/
exercises/
exercises.php
img/
incl/
index-no-include.php
index.php
js/
source.php
sql_funktion.php
style/
submissions/
viewsource.php

sql_funktion.php

41 lines UTF-8 Windows (CRLF)
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/dark.css">
  <title>Funktion</title>
</head>
<body>
  <?php
    $servername 
"localhost";
    
$username "root";
    
$password "";
    
$dbname "mindatabas";

    try {
      
$conn = new PDO("mysql:host=$servername;dbname=$dbname"$username$password);
      
// set the PDO error mode to exception
      
$conn->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);

      
// sql to create table
      
$sql "CREATE TABLE kompisar (
      idnummer INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
      förnamn VARCHAR(30) NOT NULL,
      efternamn VARCHAR(30) NOT NULL,
      mobil VARCHAR(12) NOT NULL,
      epost VARCHAR(50),
      reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
      )"
;

      
// use exec() because no results are returned
      
$conn->exec($sql);
      echo 
"Table kompisar created successfully";
    } catch(
PDOException $e) {
      echo 
$sql "<br>" $e->getMessage();
    }

    
$conn null;
  
?>
</body>
</html>