lukerodham Posted April 9, 2011 Share Posted April 9, 2011 hey guys stuck on this one cant see why it wont work, hope someone can help. im trying to just change the content not the whole page while still only a admin can see it. if you get my jist. but everytime i click the link nothing shows up for some reason. thanks in advance. <?php session_start(); include("login.php"); ?> <html> <body> <?php if(isset($_SESSION['user'])){ ?> <table width='90%' height='100%' border='1' align='center'> <tr valign='top'> <td><table width='60%' border='0' align='center'> <tr> <td colspan='3' align='center'>You've succesfully logged in.<p></td> </tr> <tr> <td><a href='index.php?page=post.php'>post news</a></td> <td><a href='index.php?page=mail.php'>mailing list</a></td> <td><a href='index.php?page=stats.php'>site stats</a></td> <td><a href='login.php?logout'>logout</a></p></td> </tr> <tr> <td colspan='3'> <?php $page = $_GET['page']; if($page){ include("inc/".$page.".php"); } ?> </td> </tr> </table></td> </tr> </table> ?> <?php } else { die(); } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/233210-dynamic-page/ Share on other sites More sharing options...
Pikachu2000 Posted April 9, 2011 Share Posted April 9, 2011 If you echo $page right after you assign its value, it should become apparent why it's not acting as you think it should. Quote Link to comment https://forums.phpfreaks.com/topic/233210-dynamic-page/#findComment-1199322 Share on other sites More sharing options...
lukerodham Posted April 9, 2011 Author Share Posted April 9, 2011 hmmm strange i echo'd it out and it saying post.php so i guess its working fine, this is the code for the post.php page which im trying to see, could you please tell me if have doing something wrong on there. thanks. <?php session_start(); if(isset($_SESSION['user'])){ echo " <h1>Post news</h1> <hr /> <form action='post.php' method='post'> Title:<br /><input type='text' name='title'> <p> Body:<br /><textarea rows='6' cols='35' name='body'></textarea><p> <input type='submit' name='post' value='post this'> </form> "; if ($_POST['post']){ $title = $_POST['title']; $body = $_POST['body']; if ($title&&$body){ mysql_connect("","",""); mysql_select_db("") or die(mysql_error()); $date = date("y-m-d"); $insert = mysql_query("INSERT INTO news VALUES ('','$title','$body','$date')") or die(mysql_error()); die("Your news has been posted."); } else echo "Please fill out title and body<p>"; } } else { die("Sorry you dont have access."); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/233210-dynamic-page/#findComment-1199375 Share on other sites More sharing options...
Pikachu2000 Posted April 9, 2011 Share Posted April 9, 2011 Yes, and that's the problem. Look at what you append to the variable in the include function . . . Quote Link to comment https://forums.phpfreaks.com/topic/233210-dynamic-page/#findComment-1199377 Share on other sites More sharing options...
Jnerocorp Posted April 9, 2011 Share Posted April 9, 2011 also on that new page you posted just looking through the code i seen a problem change: } else echo "Please fill out title and body<p>"; } to this: } else { echo "Please fill out title and body<p>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/233210-dynamic-page/#findComment-1199378 Share on other sites More sharing options...
Jnerocorp Posted April 9, 2011 Share Posted April 9, 2011 and i think what Pikachu2000 is saying look at your $page code <?php $page = $_GET['page']; if($page){ include("inc/".$page.".php"); } ?> so here is your problem: $page = $_GET['page']; <== that will get ?page=pagename.php from the url so your include("inc/".$page.".php"); <= looks like this [include("inc/pagename.php.php"); the .php is coming up as .php.php either remove the .php from ?page= or change include("inc/".$page.".php"); to include("inc/".$page.""); Quote Link to comment https://forums.phpfreaks.com/topic/233210-dynamic-page/#findComment-1199380 Share on other sites More sharing options...
Pikachu2000 Posted April 9, 2011 Share Posted April 9, 2011 Exactly. Remove the extension form the $_GET var, and tack it on in the include() function. Quote Link to comment https://forums.phpfreaks.com/topic/233210-dynamic-page/#findComment-1199398 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.