Jump to content


Photo

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


  • Please log in to reply
20 replies to this topic

#1 cameeob2003

cameeob2003
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 10 July 2006 - 06:03 AM

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")
<?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>';
	}
?>

The code the line requests to diplay:

<?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>";

?>

Here is a picture of the problem:

http://n2p.ventgamin...roblem/n2p1.jpg

#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 10 July 2006 - 06:25 AM

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

<?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
?>

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

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

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 10 July 2006 - 06:33 AM

Be sure to leave out the <?php and ?> at the beginning and end of the user_panel

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#4 cameeob2003

cameeob2003
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 10 July 2006 - 07:02 AM

Thanks that is just what i was looking for!!! :)

#5 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 10 July 2006 - 12:41 PM

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

<?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
}
?>

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.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#6 cameeob2003

cameeob2003
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 11 July 2006 - 02:38 AM

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:
<?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']);
?>

Here is the error I get:

Parse error: parse error, unexpected T_CASE in /homepages/34/d154144477/htdocs/ventgaming/n2p/loginscript/action.php on line 32



#7 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 11 July 2006 - 03:06 AM

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

if ($something==whatever) {
//do something here like echo or whatever
}else{
//do something else
}

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

This needs to be the same as the top like this
function getpage($act) {
and you need the switch statment the same thing

like this
switch ($act) {


I tried to fix your code try this

<?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
?>

You will call this script by yourscript.php?act=user_profile


Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#8 cameeob2003

cameeob2003
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 11 July 2006 - 04:19 AM

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

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:

<?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
?>

I checked to make sure I had all the lines ended and it looks to be that way but i

#9 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 11 July 2006 - 04:38 AM

Not sure but I know that error usually means that an if statement was not closed. I will mess with it and see what I come up with. In the mean time someone might be able to better anwser this question

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#10 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 11 July 2006 - 04:41 AM

try moving the last break back some like this

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
?>

I don't know if that will fix your problem or not but you can try it.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#11 cameeob2003

cameeob2003
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 11 July 2006 - 06:10 AM

No that didnt fix it is there something else that is wrong in it? Anyone care to comment?

#12 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 11 July 2006 - 08:22 AM

did your script work before you put it into the switch statement? If so then, cut what you have between the case"": and break; and paste your working script in there. Minus the <?php and ?>

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#13 Chips

Chips
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 11 July 2006 - 08:26 AM

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


#14 cameeob2003

cameeob2003
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 11 July 2006 - 10:12 AM

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

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


Here is action.php file:
<?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
?>


#15 Chips

Chips
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 11 July 2006 - 10:54 AM

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

#16 mikey123

mikey123
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 12 July 2006 - 10:55 AM

Comon where all dem good php coders at.. help him fix his problem!!!

#17 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 12 July 2006 - 11:50 AM

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

#18 mikey123

mikey123
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 12 July 2006 - 10:10 PM

SO YOUR telling me... theres no one that can help cam with his problem??? I thought we get CORRECt answers!!!!

#19 Chips

Chips
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 13 July 2006 - 10:09 AM

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?


#20 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 13 July 2006 - 11:40 AM

I agree

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users