buildBlock.php
Source of buildBlock.php
<!doctype html>
<html lang="en">
<head>
<title>buildBlock.php</title>
<meta charset="UTF-8">
</head>
<body>
<?php
//retrieve data from form
$password = filter_input(INPUT_POST, "password");
$blockType = filter_input(INPUT_POST, "blockType");
$title = filter_input(INPUT_POST, "title");
$content = filter_input(INPUT_POST, "content");
$pageID = filter_input(INPUT_POST, "pageID");
//check password
if ($password == "allInOne"){
manageResults();
} else {
print "<h2>Unauthorized access...</h2>";
} // end if
function manageResults(){
global $blockType, $title, $content, $pageID;
//return output
print <<<HERE
<h2>Page input:</h2>
<p>
blockType: $blockType <br />
title: $title <br />
content: $content <br />
pageID: $pageID
</p>
HERE;
try {
//connect to database
$con= new PDO('mysql:host=localhost;dbname=dbName', "user", "pwd");
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//create an INSERT statement based on input
$stmt = $con->prepare('INSERT INTO cmsBlock VALUES(null, ?, ?, ?, ?)');
$result = $stmt->execute(array($blockType, $title, $content, $pageID));
//provide feedback
if ($result){
print "System updated";
} else {
print "There was an error";
} // end if
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
} // end try
} // end function
?>
<p>
<a href = "dbCMS.php">return to the CMS</a>
</p>
</body>
</html>