This repository has been archived by the owner on Jul 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patheditpage.php
94 lines (86 loc) · 2.57 KB
/
editpage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
require_once ("Includes/session.php");
require_once ("Includes/simplecms-config.php");
require_once ("Includes/connectDB.php");
include("Includes/header.php");
confirm_is_admin();
$pageId = null;
$menulabel = null;
$content = null;
if(isset($_GET['id']))
{
$pageId = $_GET['id'];
$query = "SELECT menulabel, content FROM pages WHERE id = ?";
$statement = $databaseConnection->prepare($query);
$statement->bind_param('d', $pageId);
$statement->execute();
$statement->store_result();
if ($statement->error)
{
die('Database query failed: ' . $statement->error);
}
$pageExists = $statement->num_rows == 1;
if ($pageExists)
{
$statement->bind_result($menulabel, $content);
$statement->fetch();
}
else
{
header("Location: index.php");
}
}
else if (isset($_POST['submit']))
{
$pageId = $_POST['pageId'];
$menulabel = $_POST['menulabel'];
$content = $_POST['content'];
$query = "UPDATE pages SET menulabel = ?, content = ? WHERE Id = ?";
$statement = $databaseConnection->prepare($query);
$statement->bind_param('ssd', $menulabel, $content, $pageId);
$statement->execute();
$statement->store_result();
if ($statement->error)
{
die('Database query failed: ' . $statement->error);
}
$creationWasSuccessful = $statement->affected_rows == 1 ? true : false;
if ($creationWasSuccessful)
{
header ("Location: index.php");
}
else
{
echo 'Failed to edit page';
}
}
else
{
header ("Location: index.php");
}
?>
<div id="main">
<h1>Edit Page</h1>
<form action="editpage.php" method="post">
<fieldset>
<legend>Edit Page</legend>
<ol>
<li>
<input type="hidden" id="pageId" name="pageId" value="<?php echo $pageId; ?>" />
<label for="menulabel">Menu Label:</label>
<input type="text" name="menulabel" value="<?php echo $menulabel; ?>" id="menulabel" />
</li>
<li>
<label for="content">Page Content:</label>
<textarea name="content" id="content"><?php echo $content; ?></textarea>
</li>
</ol>
<input type="submit" name="submit" value="Submit" />
<p>
<a href="index.php">Cancel</a>
</p>
</fieldset>
</form>
</div>
</div> <!-- End of outer-wrapper which opens in header.php -->
<?php include ("Includes/footer.php"); ?>