Jump to content

IF Statement With Logged In Feature - specifying the query


EternalSorrow

Recommended Posts

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.