require_once('site_core.php');
require_once('site_forms.php');
require_once('site_db.php');
// Set the title of the page
$title = "Update Page";
// Echo the HTML head with title
echo_head($title);
// Echo Bootstrap container
echo '
'.$title.'
';
// Get the page id and action
$id = $_GET['id'];
$action = $_GET['action'];
// If the id is null/blank
if ($id == '') {
// Get the pageid and title of all pages
$result = run_query("SELECT pageid, title FROM pages");
// Transform it into an associative array
$pages = array();
while ($row = $result->fetch_assoc()) {
$pages[ $row['pageid'] ] = $row['title'];
}
// Generate a dropdown menu of all the pages
echo '
';
}
// If action is update
else if ($action=='update') {
// Get the posted form data
$title = $_POST['title'];
$content = addslashes($_POST['content']);
$parent = $_POST['parent'];
// Form the query
$sql = "UPDATE pages SET title = '$title', content = '$content', parent = '$parent' WHERE pageid='$id'";
// Run the query
run_query($sql);
// Echo feedback
echo '
'.$id.' was updated from pages
';
}
// If the id is given but action is not update
else {
// Get all the pages to generate the parent drop down
$result = run_query("SELECT pageid, title FROM pages");
$pages = array();
while ($row = $result->fetch_assoc()) {
$pages[ $row['pageid'] ] = $row['title'];
}
// Get the data for the selected page
$result = run_query("SELECT * FROM pages WHERE pageid='$id'");
$values = $result->fetch_assoc();
// Ouput the edit form
echo '
';
}
echo '
';
echo_foot();
?>