Jump to content

Displaying an if($_GET['page'] == "pagename"){ Question }


cameeob2003

Recommended Posts

I am using the following code to try and get my page to display in an Iframe. Both of the following bits of code are on the same page called "index.php". When I click the link it redisplays the entire page html and all without showing the coded part. The problem I have:
1) the current page displays again in the Iframe without displaying the code I am trying to display
This is what I want to happen:
1) for the code itself to display in the Iframe with no other content

Here are the bits of code I am working with:

Code that requests the ($_GET['page'] == "pagename")
[code]<?php
if(!$_SESSION['auth']){
echo '<form name="form1" method="post" action="login/checkuser.php">
<div style="position: absolute; top: 191px; left: 253px;">
<table><tr><td><font id=formtext />Username</td><td><input style="width: 100px; height= 12px;" name="username" type="text" id="username"></td></tr><tr>
<td><font id=formtext />Password</td><td><input style="width: 100px; height= 12px;" name="password" type="password" id="password"></td><tr><td>
<input style="position: absolute; top: 53px; left: 109px; background-image: url(img/login_button.gif); width: 51px; height: 15px; border: 0;" type="submit" name="Submit" value=""></td></tr></table>
</div>
</form>';
echo '<div style="position: absolute; top: 244px; left: 256px;"><a href="login/reg_form.html" target="frame1"><font id=bluesmall />Register</a></div>';
}else{
$newpms = $_SESSION['priv_messages'];
echo '<div style="position: absolute; top: 191px; left: 253px;"><font id=UserNameRed />'. $_SESSION['username'] .'<br/><a href=?page=newpmessage=$id><font id=UserPanelText />Messages</a> ('. $newpms .')<br/><font id=UserPanelText /><a href=index.php?page=user_panel target=frame1>User Panel</a><br/>

<a href="index.php?act=user_panel" target=frame1 > // <<<<---- the line that requests

Logout</a><br/></div>';
}
?>[/code]

The code the line requests to diplay:

[code]<?php
if($_GET['page'] == "user_panel");
echo "<font id=formtext />Welcome ". $_SESSION['first_name'] ." ". $_SESSION['last_name'] ."!<br /><br />";

echo "<font id=formtext />Your user level is<font id=UserNameRed /> ". $_SESSION['user_level']."<font id=formtext /> which enables
    you access to the following areas: <br />";

if($_SESSION['user_level'] == 0){
    echo "<br /><font id=UserNameRed />User Profile<br />";
}
if($_SESSION['user_level'] == 1){
    echo "- Forums<br />- Chat Room<br />- Moderator Area<br />";
}

echo "<br /><a href=logout.php><font id=formtext />Logout</a>";

?> [/code]

Here is a picture of the problem:

[url=http://n2p.ventgaming.com/problem/n2p1.jpg]http://n2p.ventgaming.com/problem/n2p1.jpg[/url]
Link to comment
Share on other sites

You might want to use a switch statement. Like this.

[code=php:0]
<?php
function getpage($showpage) {
    switch ($showpage) {
        case "user_panel":
//put the user_pannel php here
        break;
        case "your_next_page":
//put another page here
        break;
    default:
your default page
    }
}
getpage($_GET['showpage']);//you need this to execute your code
?>[/code]

Say that you put this switch statement in account.php. To get to the user_pannel you would have a link like this [b]account.php?showpage=user_pannel[/b]

You can add as many pages as you like this way just repeat the case "the_new_page". You can even have a switch statement inside of another switch statement.

Default would be your default php or html of the account page and can be linked just like before. www.yourdomain.com/account.php. That would show the default.

Hope that helps
Link to comment
Share on other sites

Another thing that I forgot to metion is that if these pages are going to be using sessions you will have to start the session at the very top of the page like this

[code=php:0]<?php
session_start()
header("Cache-control: private");
if (!$_SESSION['username']) {
    echo "your session error message";
    include("login.php");
}else{
function getpage($showpage) {
    switch ($showpage) {
        case "user_panel":
//put the user_pannel php here
        break;
        case "your_next_page":
//put another page here
        break;
    default:
//your default page
    }
}
getpage($_GET['showpage']);//you need this to execute your code
}
?>[/code]

you only need to do this once and every case"": will be covered by that session
I thought that I would post this for you because I had an issue with this and figured I would save you some time.
Link to comment
Share on other sites

Everything you said worked fine for me using the echo command but here is another problem im having. It gives me an error when i put my script to execute the insertion of data to mysql database.

Here is my code:
[code]<?php session_start();
include("config/db.php");?>
<?php
function getpage($showpage) {
    switch ($showpage) {
        case "user_profile":

$steamid = $_POST['steamid'];
$handle = $_POST['handle'];
$team_name = $_POST['team_name'];
$team_tag = $_POST['team_tag'];


# out with any unwanted characters
$steamid = stripslashes($steamid);
$handle = stripslashes($handle);
$team_name = stripslashes($team_name);
$team_tag = stripslashes($team_tag);

# insert data into database
$info2 = htmlspecialchars($info);
$sql = mysql_query("UPDATE users SET steamid='$steamid', handle='$handle', team_name='$team_name', team_tag='$team_tag' WHERE id='$id'") or die (mysql_error());

if(!$sql){
echo '<font id=UserNameRed />There has been an error entering the data. Please contact the webmaster.';
}else{
echo '<font id=UserNameRed />The data was entered successfully.';
}
}
}
        break;
        case "add_news": // <<<<---- ERORR MESSAGE LINE 32

$author = $_SESSION['user'];
$title = $_POST['title'];
$ndate = $_POST['date'];
$news = $_POST['news'];

# out with any unwanted characters
$title = stripslashes($title);
$ndate = stripslashes($ndate);
$news = stripslashes($news);

# insert data into database
$description2 = htmlspecialchars($description);
$sql = mysql_query("INSERT INTO news (date, author, title, news) VALUES ('$ndate','$author','$title','$news')") or die (mysql_error());

if(!$sql){
echo '<font id=UserNameRed />There has been an error entering the data. Please contact the webmaster.';
}else{
echo '<font id=UserNameRed />The data was entered successfully.';
}
}

break;
    }
}
getpage($_GET['act']);
?>[/code]

Here is the error I get:
[quote]
Parse error: parse error, unexpected T_CASE in /homepages/34/d154144477/htdocs/ventgaming/n2p/loginscript/action.php on line 32[/quote]
Link to comment
Share on other sites

ok I saw several syntax errors in this script. First was the double <?php ?> at the begining of your file. Second is your use of the if/ else statements. Here is an example of how you should form your if/else statments

[code=php:0]if ($something==whatever) {
//do something here like echo or whatever
}else{
//do something else
}[/code]

Third was the end of the file. The [code]getpage($_GET['act']);[/code]

This needs to be the same as the top like this
[code=php:0]function getpage($act) {[/code] and you need the switch statment the same thing

like this [code=php:0]switch ($act) {[/code]


I tried to fix your code try this

[code]<?php
session_start();
header("Cache-control: private");
if (!$_SESSION['username']) {   
    echo "your session error message";
    include("login.php");
/*you need to add some kind of if statement that will
redirect users that are not loged in to the login page.
You can change ['username'] to what ever you use
for sessions*/
}else{
include("config/db.php");
function getpage($act) {
    switch ($act) {
        case "user_profile":
$steamid = $_POST['steamid'];
$handle = $_POST['handle'];
$team_name = $_POST['team_name'];
$team_tag = $_POST['team_tag'];


# out with any unwanted characters
$steamid = stripslashes($steamid);
$handle = stripslashes($handle);
$team_name = stripslashes($team_name);
$team_tag = stripslashes($team_tag);

# insert data into database
$info2 = htmlspecialchars($info);
$sql = mysql_query("UPDATE users SET steamid='$steamid', handle='$handle', team_name='$team_name', team_tag='$team_tag' WHERE id='$id'") or die (mysql_error());

if(!$sql){
echo '<font id=UserNameRed />There has been an error entering the data. Please contact the webmaster.';
}else{
echo '<font id=UserNameRed />The data was entered successfully.';
}
        break;
        case "add_news": // <<<<---- ERORR MESSAGE LINE 32

$author = $_SESSION['user'];
$title = $_POST['title'];
$ndate = $_POST['date'];
$news = $_POST['news'];

# out with any unwanted characters
$title = stripslashes($title);
$ndate = stripslashes($ndate);
$news = stripslashes($news);

# insert data into database
$description2 = htmlspecialchars($description);
$sql = mysql_query("INSERT INTO news (date, author, title, news) VALUES ('$ndate','$author','$title','$news')") or die (mysql_error());

if(!$sql){
echo '<font id=UserNameRed />There has been an error entering the data. Please contact the webmaster.';
}else{
echo '<font id=UserNameRed />The data was entered successfully.';
}
break;
    }
}
getpage($_GET['act']);// this needs to be the same as the switch statement and the start of the function
?>[/code]

You will call this script by [b]yourscript.php?act=user_profile[/b]

Link to comment
Share on other sites

All looked as though it would go well but now I have this error:
[code]
Parse error: parse error, unexpected $ in /homepages/34/d154144477/htdocs/ventgaming/n2p/loginscript/action.php on line 62[/code]

If i remember right this happens when the session_start(); is not the first line of code so i put it as the first line but with no luck. So i then checked the other lines of code and from what I saw no errors were present. Is there an error Im missing? (Well obviously)

The code:

[code]<?php session_start();
header("Cache-control: private");
if ($_SESSION['auth'] = false) {   
    echo "Please login before tyring to access this area";
    include("index.php");
/*you need to add some kind of if statement that will
redirect users that are not loged in to the login page.
You can change ['username'] to what ever you use
for sessions*/
}else{
include("config/db.php");
function getpage($act) {
    switch ($act) {
        case "user_profile":
$steamid = $_POST['steamid'];
$handle = $_POST['handle'];
$team_name = $_POST['team_name'];
$team_tag = $_POST['team_tag'];


# out with any unwanted characters
$steamid = stripslashes($steamid);
$handle = stripslashes($handle);
$team_name = stripslashes($team_name);
$team_tag = stripslashes($team_tag);

# insert data into database
$info2 = htmlspecialchars($info);
$sql = mysql_query("UPDATE users SET steamid='$steamid', handle='$handle', team_name='$team_name', team_tag='$team_tag' WHERE id='$id'") or die (mysql_error());

if(!$sql){
echo '<font id=UserNameRed />There has been an error entering the data. Please contact the webmaster.';
}else{
echo '<font id=UserNameRed />The data was entered successfully.';
}
        break;
        case "add_news":

$author = $_SESSION['user'];
$title = $_POST['title'];
$ndate = $_POST['date'];
$news = $_POST['news'];

# out with any unwanted characters
$title = stripslashes($title);
$ndate = stripslashes($ndate);
$news = stripslashes($news);

# insert data into database
$description2 = htmlspecialchars($description);
$sql = mysql_query("INSERT INTO news (date, author, title, news) VALUES ('$ndate','$author','$title','$news')") or die (mysql_error());

if(!$sql){
echo '<font id=UserNameRed />There has been an error entering the data. Please contact the webmaster.';
}else{
echo '<font id=UserNameRed />The data was entered successfully.';
}
break;
    }
}
getpage($_GET['act']);// this needs to be the same as the switch statement and the start of the function
?>[/code]

I checked to make sure I had all the lines ended and it looks to be that way but i
Link to comment
Share on other sites

try moving the last break back some like this

[code=php:0]if(!$sql){
echo '<font id=UserNameRed />There has been an error entering the data. Please contact the webmaster.';
}else{
echo '<font id=UserNameRed />The data was entered successfully.';
}
        break;
    }
}
getpage($_GET['act']);// this needs to be the same as the switch statement and the start of the function
?>[/code]

I don't know if that will fix your problem or not but you can try it.
Link to comment
Share on other sites

Just had a really quick look, all i saw was this:
[code]
if ($_SESSION['auth'] = false) {    [/code]
that's an assignment operator, and not an equivalence... it should be:
[code]
if ($_SESSION['auth'] == false) {    [/code]
Link to comment
Share on other sites

I tested that and that was not the problem I am still getting  the following error:

[quote]Parse error: parse error, unexpected $ in /homepages/34/d154144477/htdocs/ventgaming/n2p/loginscript/action.php on line 62[/quote]

Here is action.php file:
[code]
<?php session_start();
header("Cache-control: private");
if ($_SESSION['auth'] == false) {   
    echo "Please login before tyring to access this area";
    include("index.php");
/*you need to add some kind of if statement that will
redirect users that are not loged in to the login page.
You can change ['username'] to what ever you use
for sessions*/
}else{
include("config/db.php");
function getpage($act) {
    switch ($act) {
        case "user_profile":
$steamid = $_POST['steamid'];
$handle = $_POST['handle'];
$team_name = $_POST['team_name'];
$team_tag = $_POST['team_tag'];


# out with any unwanted characters
$steamid = stripslashes($steamid);
$handle = stripslashes($handle);
$team_name = stripslashes($team_name);
$team_tag = stripslashes($team_tag);

# insert data into database
$info2 = htmlspecialchars($info);
$sql = mysql_query("UPDATE users SET steamid='$steamid', handle='$handle', team_name='$team_name', team_tag='$team_tag' WHERE id='$id'") or die (mysql_error());

if(!$sql){
echo '<font id=UserNameRed />There has been an error entering the data. Please contact the webmaster.';
}else{
echo '<font id=UserNameRed />The data was entered successfully.';
}
        break;
        case "add_news":

$author = $_SESSION['user'];
$title = $_POST['title'];
$ndate = $_POST['date'];
$news = $_POST['news'];

# out with any unwanted characters
$title = stripslashes($title);
$ndate = stripslashes($ndate);
$news = stripslashes($news);

# insert data into database
$description2 = htmlspecialchars($description);
$sql = mysql_query("INSERT INTO news (date, author, title, news) VALUES ('$ndate','$author','$title','$news')") or die (mysql_error());

if(!$sql){
echo '<font id=UserNameRed />There has been an error entering the data. Please contact the webmaster.';
}else{
echo '<font id=UserNameRed />The data was entered successfully.';
}
break;
    }
}
getpage($_GET['act']);// this needs to be the same as the switch statement and the start of the function
?>[/code]
Link to comment
Share on other sites

I see no $info declaration, no $description declaration - both of which are referenced as variables passed to functions. Also, where is this action.php mentioned, nothing appears in this thread about it, EXCEPT for your error message. Bit baffled... mind you, I am new to this myself :P
Link to comment
Share on other sites

You need one more end curly brace at the end of your script to end your if statement.

If you had properly indented your code, you would have seen the missing brace.

BTW, if you're only using the function once, there's no real reason not to put the code inline.

Ken
Link to comment
Share on other sites

Tis weird how your first two posts are only in this thread, and only criticising those who have attempted to help as well as anyone else. Remember that no-one gets paid to help here, it's all people volunteering up their free time to try and solve others issues, just because they are nice enough to care/bother.

I try my best with my very limited knowledge, but no-one can read every single topic and comment/help out - there isn't time in the day, and they all have jobs to work at too (bit like myself). They pick topics by the title/name I would imagine, and then may attempt to help. I only read a few threads per day, ones where I feel i may know what is being talked about - others may target threads that get no replies...

As it is, I would imagine the lack of response to the thread is due to the actual thread creator not updating/informing anyone about progress or further issues. For all you know, he may have posted this elsewhere as well, where they solved it. Anyone trying to sort this now could be wasting their time unless the original poster comes back and asks for further help as problems still exist.

However, all that is by the by - I just really wanted to say that your attitude is pretty appalling, and wouldn't endeer me to help anyone who behaves like that. Is that really how you intended to get this guy help?
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.