Jump to content

$_GET variable error


Skatecrazy1

Recommended Posts

having a problem using get variables to include certain pages.  I have a management script for a news feed that uses get variables to display certain parts of the script.  here is the template/ main part of the script

 

<?php
session_start();
require_once("vars.php");
$username = $_SESSION['username'];
$is_admin = $_SESSION['is_admin'];
$referer = $_SERVER['HTTP_REFERER'];
//check to see if user is logged in and is an administrator
if((isset($_SESSION['username'])) && ($_SESSION['is_admin'] == 1)){
//if all session variables are set, display admin panel
?>
<html>
    <head>
        <title>Administration</title>
        <link rel="stylesheet" type="text/css" href="/cameo/css/admin.css" media="screen" />
    </head>
    <body>
<table cellspacing="0" cellpadding="3" class="layout">
    <tr>
        <td colspan="2"><h3>Administration</h3></td>
    </tr>
    <tr>
        <td valign="top">
            <a href="index.php?pg=news">Manage News Feed</a>
        </td>
        <td>
            <?php
             $id = $_GET['pg'];
             switch($id){
                case news:
                    include("manage_news.php");
                case editpost:
                    include('edit_post.php');
                    break;
             }
             ?>
        </td>
    </tr>
</table>
    </body>
</html>
<?php

} else {
  echo("You do not have permission to view this page. <br />");
  echo("<a href=\"".$referer."\">Go Back</a>");
}
?>

 

and heres the edit post page that the script refers to

 

<?php
require_once("vars.php");
$id = $_GET['id'];
$query = "SELECT * FROM news_feed WHERE id=".$id;
$result = mysqli_query($dbc,$query);
$row = mysqli_fetch_array($result);
?>
<form method="post" action="update.php">
    <textarea><?php echo $row['post_body']; ?></textarea>
</form>

 

now, for some reason, the edit post form is showing up under the main news feed listing, even though the get id does not match the one in the switch statement.  thanks in advance for any help

Link to comment
Share on other sites

1. Use quotes around a string like in your case statement, it should be:

 

case 'news':

 

2. You haven't included a break in the news case, that is why the edit form always shows, it should be

 

                case 'news':
                    include("manage_news.php");
                    break; // this was missing
                case 'editpost':
                    include('edit_post.php');
                    break;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.