EternalSorrow Posted August 17, 2009 Share Posted August 17, 2009 I have implemented an (old) login system into my site which I found here. The difficulty I'm having is with the content guests and users are allowed to view. I've created a field, here called $nom, which when identified in the database signifies a guest is allowed to view the information. The login script uses the simple code snippet if(!$session->logged_in) { to signify what the users can view, and an ELSE for what guests can view. What I can't figure out is a way to execute a query, here using an IF statement, which will show what users are allowed to view, and a simple ELSE which will show guests what they are allowed to view. Here's the IF statement I've put together to try to specify the guests from the users, but when viewed logged in or not the result is always the same: if(!$session->logged_in) { echo '<li><a href="info.php?author='.$author.'&title='.$title.'">'.$title.'</a></li>'; } else { $result_section = "SELECT * FROM archives WHERE nom = 'no' LIMIT 1 "; $results = mysql_query( $result_section ) or die(mysql_error()); while ($section = mysql_fetch_assoc($results)) { echo '<li><a href="info.php?author='.$author.'&title='.$title.'">'.$title.'</a></li>'; } } I can't figure out what's wrong, and no error message appears telling me my code is wrong. Anyone have any ideas? Here's the code in its entirety: <?php if (!is_numeric($_GET["author"]) && !empty($_GET["author"]) && $_GET["author"]!="") { $author = $_GET["author"]; } mysql_connect(localhost,user,pw); @mysql_select_db(db) or die( "Unable to select database"); $query = sprintf("SELECT DISTINCT title, url, archives.nom FROM archives LEFT JOIN author ON author.id = archives.id WHERE `author`= '%s' ORDER BY title ", mysql_real_escape_string($author)) or die(mysql_error()); $result = mysql_query( $query ) or die(mysql_error()); $i=1; echo '<h1>'.$author.'</h1><ol> <li>Authored Titles: <ol class="titles">'; while ($row = mysql_fetch_array($result)) { extract($row); if(!$session->logged_in) { echo '<li><a href="info.php?author='.$author.'&title='.$title.'">'.$title.'</a></li>'; } else { $result_section = "SELECT * FROM archives WHERE nom = 'no' LIMIT 1 "; $results = mysql_query( $result_section ) or die(mysql_error()); while ($section = mysql_fetch_assoc($results)) { echo '<li><a href="info.php?author='.$author.'&title='.$title.'">'.$title.'</a></li>'; } } } echo '</ol></li>'; ?> </ol> Link to comment https://forums.phpfreaks.com/topic/170572-if-statement-with-logged-in-feature-specifying-the-query/ Share on other sites More sharing options...
EternalSorrow Posted August 17, 2009 Author Share Posted August 17, 2009 As a bump, here is a question I gave which is in a similar vein: link here And here are a few related links, such as where I got the basics for this script. Link to comment https://forums.phpfreaks.com/topic/170572-if-statement-with-logged-in-feature-specifying-the-query/#findComment-900053 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.