mrooks1984 Posted March 31, 2011 Share Posted March 31, 2011 hello i am stuck and hoping you can help, i have created this function and its not working correctly, what i am trying to do is when someone is logged in they get this line of code echo "<a href=\"update-content.php?id=5\">Edit</a> | <a href=\"delete-content.php?id=5\">Delete</a>"; which is ok as i dont want that to work yet and if your not logged in you dont get it. i have added //show when logged in and show not logged in so you know which code i want it to load when at the moment its only loading the not logged in one even if you are. i have looked on google read up on php sites but cant figure out how to do it, so hoping you guys will tell me were i gone wrong and how to correct it, thanks again heres the code. function get_left() { if (isset($_GET['page'])) { $page = $_GET['page']; //Show Page not logged in $sql = "SELECT title,body FROM content WHERE page = '$page' AND location = 'left' AND disabled = 'no' ORDER BY id"; $res = mysql_query($sql) or die (mysql_error()); while($row = mysql_fetch_assoc($res)){ echo '<h1>' . $row['title'] . '</h1>'; echo '<p>' . $row['body'] . '</p>'; } } //show when logged in elseif ($_SESSION['username']&&(isset($_GET['page']))){ $sql = "SELECT title,body FROM content WHERE page = '$page' AND location = 'left' AND disabled = 'no' ORDER BY id"; $res = mysql_query($sql) or die (mysql_error()); while($row = mysql_fetch_assoc($res)){ echo '<h1>' . $row['title'] . '</h1>'; echo '<p>' . $row['body'] . '</p>'; echo "<a href=\"update-content.php?id=5\">Edit</a> | <a href=\"delete-content.php?id=5\">Delete</a>"; } } } Quote Link to comment Share on other sites More sharing options...
litebearer Posted March 31, 2011 Share Posted March 31, 2011 As a start, your IF and your ELSEIF both check to see if $_GET page is set, if it is, then the ELSEIF will never execute as the first portion will kick-in - you need to rethink the order ie first if BOTH username and page are set do this - if only page is set do that. Quote Link to comment Share on other sites More sharing options...
mrooks1984 Posted March 31, 2011 Author Share Posted March 31, 2011 thanks for your responce, could you show me a example, still not show how to do it but i know where you are coming from Quote Link to comment Share on other sites More sharing options...
litebearer Posted March 31, 2011 Share Posted March 31, 2011 Simply reverse the if and elseif conditions - FIRST check to see if username and page are set then in the elseif check to see if the page is set. By reversing the order, if username not set, it will then check if the page is set in the elseif. Of course you haven't provided for the condition where neither is set. capice? Quote Link to comment Share on other sites More sharing options...
mrooks1984 Posted March 31, 2011 Author Share Posted March 31, 2011 thanks for your help again ok i now have this, when logged in it shows the correct stuff, if i then log out it does not show anything at all? i must be missing something elise? function get_left() { if ($_SESSION['username']&&(isset($_GET['page']))) { $page = $_GET['page']; //Show Page not logged in $sql = "SELECT title,body FROM content WHERE page = '$page' AND location = 'left' AND disabled = 'no' ORDER BY id"; $res = mysql_query($sql) or die (mysql_error()); while($row = mysql_fetch_assoc($res)){ echo '<h1>' . $row['title'] . '</h1>'; echo '<p>' . $row['body'] . '</p>'; echo "<a href=\"update-content.php?id=5\">Edit</a> | <a href=\"delete-content.php?id=5\">Delete</a>"; } } //show when logged in elseif (isset($_GET['page'])){ $sql = "SELECT title,body FROM content WHERE page = '$page' AND location = 'left' AND disabled = 'no' ORDER BY id"; $res = mysql_query($sql) or die (mysql_error()); while($row = mysql_fetch_assoc($res)){ echo '<h1>' . $row['title'] . '</h1>'; echo '<p>' . $row['body'] . '</p>'; } } } Quote Link to comment Share on other sites More sharing options...
litebearer Posted March 31, 2011 Share Posted March 31, 2011 do a simple echo of your variables just BEFORE you call your function to verify they contain what you expect them to contain. Quote Link to comment 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.