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
https://forums.phpfreaks.com/topic/223074-_get-variable-error/
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
https://forums.phpfreaks.com/topic/223074-_get-variable-error/#findComment-1153321
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.