cameeob2003 Posted July 10, 2006 Share Posted July 10, 2006 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 displayThis is what I want to happen:1) for the code itself to display in the Iframe with no other contentHere are the bits of code I am working with:Code that requests the ($_GET['page'] == "pagename")[code]<?phpif(!$_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 requestsLogout</a><br/></div>'; }?>[/code]The code the line requests to diplay:[code]<?phpif($_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] Quote Link to comment https://forums.phpfreaks.com/topic/14144-displaying-an-if_getpage-pagename-question/ Share on other sites More sharing options...
tomfmason Posted July 10, 2006 Share Posted July 10, 2006 You might want to use a switch statement. Like this.[code=php:0]<?phpfunction 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 Quote Link to comment https://forums.phpfreaks.com/topic/14144-displaying-an-if_getpage-pagename-question/#findComment-55410 Share on other sites More sharing options...
tomfmason Posted July 10, 2006 Share Posted July 10, 2006 Be sure to leave out the <?php and ?> at the beginning and end of the user_panel Quote Link to comment https://forums.phpfreaks.com/topic/14144-displaying-an-if_getpage-pagename-question/#findComment-55415 Share on other sites More sharing options...
cameeob2003 Posted July 10, 2006 Author Share Posted July 10, 2006 Thanks that is just what i was looking for!!! :) Quote Link to comment https://forums.phpfreaks.com/topic/14144-displaying-an-if_getpage-pagename-question/#findComment-55419 Share on other sites More sharing options...
tomfmason Posted July 10, 2006 Share Posted July 10, 2006 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]<?phpsession_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 sessionI thought that I would post this for you because I had an issue with this and figured I would save you some time. Quote Link to comment https://forums.phpfreaks.com/topic/14144-displaying-an-if_getpage-pagename-question/#findComment-55502 Share on other sites More sharing options...
cameeob2003 Posted July 11, 2006 Author Share Posted July 11, 2006 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");?><?phpfunction 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] Quote Link to comment https://forums.phpfreaks.com/topic/14144-displaying-an-if_getpage-pagename-question/#findComment-55967 Share on other sites More sharing options...
tomfmason Posted July 11, 2006 Share Posted July 11, 2006 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 willredirect 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] Quote Link to comment https://forums.phpfreaks.com/topic/14144-displaying-an-if_getpage-pagename-question/#findComment-55978 Share on other sites More sharing options...
cameeob2003 Posted July 11, 2006 Author Share Posted July 11, 2006 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 willredirect 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 Quote Link to comment https://forums.phpfreaks.com/topic/14144-displaying-an-if_getpage-pagename-question/#findComment-56006 Share on other sites More sharing options...
tomfmason Posted July 11, 2006 Share Posted July 11, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/14144-displaying-an-if_getpage-pagename-question/#findComment-56014 Share on other sites More sharing options...
tomfmason Posted July 11, 2006 Share Posted July 11, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14144-displaying-an-if_getpage-pagename-question/#findComment-56018 Share on other sites More sharing options...
cameeob2003 Posted July 11, 2006 Author Share Posted July 11, 2006 No that didnt fix it is there something else that is wrong in it? Anyone care to comment? Quote Link to comment https://forums.phpfreaks.com/topic/14144-displaying-an-if_getpage-pagename-question/#findComment-56036 Share on other sites More sharing options...
tomfmason Posted July 11, 2006 Share Posted July 11, 2006 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/14144-displaying-an-if_getpage-pagename-question/#findComment-56055 Share on other sites More sharing options...
Chips Posted July 11, 2006 Share Posted July 11, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/14144-displaying-an-if_getpage-pagename-question/#findComment-56058 Share on other sites More sharing options...
cameeob2003 Posted July 11, 2006 Author Share Posted July 11, 2006 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 willredirect 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] Quote Link to comment https://forums.phpfreaks.com/topic/14144-displaying-an-if_getpage-pagename-question/#findComment-56084 Share on other sites More sharing options...
Chips Posted July 11, 2006 Share Posted July 11, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/14144-displaying-an-if_getpage-pagename-question/#findComment-56101 Share on other sites More sharing options...
mikey123 Posted July 12, 2006 Share Posted July 12, 2006 Comon where all dem good php coders at.. help him fix his problem!!! Quote Link to comment https://forums.phpfreaks.com/topic/14144-displaying-an-if_getpage-pagename-question/#findComment-56705 Share on other sites More sharing options...
kenrbnsn Posted July 12, 2006 Share Posted July 12, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/14144-displaying-an-if_getpage-pagename-question/#findComment-56724 Share on other sites More sharing options...
mikey123 Posted July 12, 2006 Share Posted July 12, 2006 SO YOUR telling me... theres no one that can help cam with his problem??? I thought we get CORRECt answers!!!! Quote Link to comment https://forums.phpfreaks.com/topic/14144-displaying-an-if_getpage-pagename-question/#findComment-56989 Share on other sites More sharing options...
Chips Posted July 13, 2006 Share Posted July 13, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/14144-displaying-an-if_getpage-pagename-question/#findComment-57204 Share on other sites More sharing options...
tomfmason Posted July 13, 2006 Share Posted July 13, 2006 [b]I agree[/b] Quote Link to comment https://forums.phpfreaks.com/topic/14144-displaying-an-if_getpage-pagename-question/#findComment-57243 Share on other sites More sharing options...
kenrbnsn Posted July 13, 2006 Share Posted July 13, 2006 Besides, I gave the answer 11 hours before this person complained for a 2nd time....Ken Quote Link to comment https://forums.phpfreaks.com/topic/14144-displaying-an-if_getpage-pagename-question/#findComment-57245 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.