I am currently working on a PHP CMS and am trying to create a edit page for a news system.
when the user goes to the edit page and a article has not been selected yet, they should get a form to select an article to edit.
When the user selects an article to edit, the page should (refresh?) display a form with the selected articles content to be edited.
all of my pages are included within my index.php based on p=pagename being set.
When I go to the edit news page I see http://puu.sh/fhYO7/569146d037.png (which is correct).
When I select a news article to edit it sends me to http://puu.sh/fhZ13/2ca0f7d974.png with the url as: mysite.com/admin/editnews.php?id=4
if I manually enter what the URL should be: mysite.com/admin/index.php?p=editnews&id=4 i get this - http://puu.sh/fhZ6h/d38e97d0bb.png
My current code: editnews.php
<?php
ob_start();
session_start();
include_once('includes/connection.php');
include_once('includes/news.php');
$news = new AdminNews;
if (isset($_SESSION['logged_in'])) {
$newss = $news->fetch_all();
if (isset($_POST['title'], $_POST['content'])) {
$title = $_POST['title'];
$content = br2nl($_POST['content']);
if (empty($title) or empty($content)) {
$error = 'All fields are required!';
header('Location: index.php?p=editnews');
} else {
global $pdo;
$query = $pdo->prepare('UPDATE admin_news SET news_title = ?, news_content = ? WHERE news_id=?');
$query->bindValue(1, $title);
$query->bindValue(2, $content);
$query->bindValue(3, $id);
$query->execute();
header('Location: index.php');
}
}
if (isset($_GET['id'])) {
$id = $_GET['id'];
?>
<!-- POST -->
<div class="post">
<div class="topwrap">
<div class="userinfo pull-left">
<div class="avatar">
<img src="images/avatar.jpg" alt="" />
<div class="status green"> </div>
</div>
<div class="icons">
<img src="images/icon1.jpg" alt="" /><img src="images/icon4.jpg" alt="" /><img src="images/icon5.jpg" alt="" /><img src="images/icon6.jpg" alt="" />
</div>
</div>
<div class="posttext pull-left">
<h2>Edit News</h2>
<?php if (isset($error)) { ?>
<small><?php echo $error; ?></small>
<?php } ?>
<!-- add news form start !-->
<form action="editnews.php" method="post" autocomplete="off">
<input type="text" name="title" value="<?php echo $news['news_title'] ?> /><br /><br />
<textarea rows="10" cols="87" value="<?php echo $news['news_content'] ?>" name="content" /></textarea>
<!-- add news form break !-->
</div>
<div class="clearfix"></div>
</div>
<div class="postinfobot">
<div class="dateposted pull-right">
<!-- add news form continue !-->
<input class="btn btn-primary" type="submit" value="Submit Changes" />
</form>
<!-- add news form end !-->
</div>
<div class="clearfix"></div>
</div>
</div>
<!-- POST -->
<?php
} else {
?>
<!-- POST -->
<div class="post">
<div class="topwrap">
<div class="userinfo pull-left">
</div>
<div class="posttext pull-left">
<h2>Select a News Post to Delete</h2>
<!-- form start !-->
<form action="editnews.php" method="get" autocomplete="off">
<select name="id">
<?php foreach ($newss as $news) { ?>
<option value="<?php echo $news['news_id']; ?>">
<?php echo $news['news_title']; ?>
</option>
<?php } ?>
</select>
<!-- form break !-->
</div>
<div class="clearfix"></div>
</div>
<div class="postinfobot">
<div class="dateposted pull-right">
<!-- form continue !-->
<input class="btn btn-primary" type="submit" value="Edit News" />
</form>
<!-- form end !-->
</div>
<div class="clearfix"></div>
</div>
</div>
<!-- POST -->
<?php
}
} else {
header('Location: index.php');
}
?>
I am completely lost on this one (just started getting back into PHP after 10+ years away from it).
The Question is: what am I doing wrong, why isnt it sending me to the correct url, why is it displaying strange when I enter what the URL should be?