Webbserverprogrammering 1

Show sourcecode

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

webbserverprogrammering/exercises/mysqlintro/kompisar/

createtable.php
dbconnection.php
deletepost.php
deletetable.php
index.html
insertdefaultposts.php
insertpost.php
selectposts.php
updatepost.php

insertdefaultposts.php

52 lines UTF-8 Windows (CRLF)
<!-- insertdefaultposts.php -->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>insertdefaultposts</title>
</head>

<body>
<?php
include ('dbconnection.php');
try {
    
$sql "INSERT INTO pdodemotable (firstname, lastname, email, phone, reg_date) 
    VALUES ('Kalle', 'Anka', 'kalle@anka.se', '0722255612', now())"
;
    
// use exec() because no results are returned
    
$dbconn->exec($sql);

    
/*** prepare the SQL statement ***/
    
$sql "INSERT INTO pdodemotable (firstname, lastname, email, phone, reg_date) 
    VALUES ('Åsa', 'Anka', 'kalle@anka.se', '0722255612', now())"
;
    
$stmt $dbconn->prepare($sql);
    
/*** execute the prepared statement ***/
    
$stmt->execute();

     
# sql
    
$sql "INSERT INTO pdodemotable (firstname, lastname, email, phone, reg_date) 
    VALUES (?, ?, ?, ?, now())"
;
    
# prepare
    
$stmt $dbconn->prepare($sql);
    
# the data we want to insert
    
$data = array('Östen''Anka''osten@anka.se''123321456');
     
# execute width array-parameter
    
$stmt->execute($data);
    
    
$data = array('Amanda''Anka''amanda@anka.se''123321456');
    
$stmt->execute($data);
    
    
$data = array('Per''Anka''pelle@anka.se''123321456');
    
$stmt->execute($data);    
    echo 
"New records created successfully";
}
catch(
PDOException $e)
    {
    echo 
$sql "<br>" $e->getMessage();
}

$dbconn null;

?>
<button onclick="window.location.href='index.html'">Meny</button>
</body>
</html>