提交主题为外键的页面的代码不起作用。它只是将我重定向到manage_content.php页面。我已经尝试更改查询和所有其他的东西,但它不起作用。我主要是这样做,以提高我的代码质量,所以如果你有任何建议。 功能页面使用
function find_selected_page(){
global $current_subject;
global $current_page;
if (isset($_GET["subject"])) {
$current_subject= find_subject_by_id($_GET["subject"]);
$current_page = null;
} elseif (isset($_GET["page"])) {
$current_subject=null;
$current_page= find_page_by_id($_GET["page"]);
} else {
$current_subject=null;
$current_page=null;
}
}
页:
<?php find_selected_page(); ?>
<?php if (!$current_subject){
redirect_to("manage_content.php");
} ?>
<?php
if (isset($_POST['submit'])) {
$subject_id = $current_subject["id"];
$menu_name = $_POST["menu_name"];
$position = (int) $_POST["position"];
$visible = (int) $_POST["visible"];
$content = $_POST["content"];
$menu_name=mysqli_real_escape_string($connection,$menu_name);
$query = "INSERT INTO pages ( subject_id, menu_name, position, visible, content) VALUES ( {$subject_id} '{$menu_name}', {$position}, {$visible}, '{$content}')";
$result=mysqli_query($connection, $query);
if($result){
$_SESSION ["message"] = "Page created";
redirect_to("manage_content.php");
} else{
$_SESSION ["message"] = "Page Not Created";
redirect_to("new_page.php");
}
} else {
redirect_to("new_page.php");
}
?>
<?php include("../includes/layouts/header.php"); ?>
<div id="main">
<div id="navigation">
<ul>
<?php $result= find_all_subjects(); ?>
<?php
while ($subject=mysqli_fetch_assoc($result)) {
?>
<li><a href="manage_content.php?subject=<?php echo urlencode($subject["id"]);?>"><?php echo $subject["menu_name"]; ?></a>
<?php $page_set = find_pages_for_subject($subject["id"]); ?>
<ul>
<?php
while ($page=mysqli_fetch_assoc($page_set)) {
?>
<li><a href="manage_content.php?page=<?php echo urlencode($page["id"]);?>"><?php echo $page["menu_name"]; ?></a></li>
<?php
}
?>
<?php mysqli_free_result($page_set); ?>
</ul>
</li>
<?php
}
?>
<?php mysqli_free_result($result); ?>
</ul>
</div>
<div id="page">
<?php echo message(); ?>
<form class="" action="new_page.php?subject=<?php echo $current_subject["id"];?>" method="post">
<p>Menu Name:
<input type="text" name="menu_name" value=""/>
</p>
<p>Position:
<select name="position">
<?php
$page_set=find_pages_for_subject($current_subject["id"]);
$page_count=mysqli_num_rows($page_set);
for ($i=1; $i <=($page_count +1) ; $i++) {
echo "<option value=\"{$i}\">{$i}</option>";
} ?>
</select>
</p>
<p>visible
<input type="radio" name="visible" value="0"/>No
<input type="radio" name="visible" value="1"/>Yes
</p>
<p>Content</br>
<textarea name="content" rows="20" cols="80"></textarea>
</p>
<input type="submit" name="submit" value="Create Page"/>
</form>
</br>
<a href="manage_Content.php">Cancel</a>
</div>
</div>