supermerc Posted March 11, 2007 Share Posted March 11, 2007 Hey, im trying to make this page viewable to only admins or mods, to my site. I store the user level in session and I know it works because I echoed it out and it gives me the right numbers here is my code <?php if($_SESSION['s_level'] < 1) { // Session is not set OR Session is less than 1 header("Location: index.php"); exit(); } ?> <HTML> <HEAD> <TITLE>Post News</TITLE> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> </HEAD> <BODY> <?php if (isset($addnews)): ?> <FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST> <p>Type the authors name here:<BR> <input size="25" NAME="author"> <p>Type news title here:<BR> <input size="25" NAME="newstitle"> <P>Type your news here:<BR> <TEXTAREA NAME="newstext" ROWS=10 COLS=40 WRAP> </TEXTAREA><BR> <INPUT TYPE=SUBMIT NAME="submitnews" VALUE="SUBMIT"> </FORM> <?php else: // Connect to the database $dbcnx = @mysql_connect( "lochgfhfst", "rahfghogfhdom", "ilfghfgm"); if (!$dbcnx) { echo( "<P>Unable to connect to the " . "database server at this time.</P>" ); exit(); } // the news database if (! @mysql_select_db("rahfghfom") ) { echo( "<P>Unable to locate the news " . "database at this time.</P>" ); exit(); } if ("SUBMIT" == $submitnews) { $sql = "INSERT INTO News SET " . "NewsText='$newstext', " . "author='$author', " . "NewsTitle='$newstitle', " . "NewsDate=now()"; if (mysql_query($sql)) { echo("<P>Your news has been added.</P>"); } else { echo("<P>Error adding submitted news: " . mysql_error() . "</P>"); } } if (isset($deletenews)) { $sql = "DELETE FROM News " . "WHERE ID=$deletenews"; if (mysql_query($sql)) { echo("<P>The news has been deleted.</P>"); } else { echo("<P>Error deleting news: " . mysql_error() . "</P>"); } } echo("<P> Here are all the news " . "in our database: </P>"); $result = mysql_query( "SELECT ID, NewsText FROM News"); if (!$result) { echo("<P>Error performing query: " . mysql_error() . "</P>"); exit(); } while ( $row = mysql_fetch_array($result) ) { $newsid = $row["ID"]; $newstext = $row["NewsText"]; echo("<P>$newstext " . "<A HREF='$PHP_SELF?deletenews=$newsid'>" . "Delete this News</A></P>"); } echo("<P><A HREF='$PHP_SELF?addnews=1'>" . "Add News!</A></P>"); endif; ?> </BODY> </HTML> Link to comment https://forums.phpfreaks.com/topic/42242-solved-if-statement/ Share on other sites More sharing options...
paul2463 Posted March 11, 2007 Share Posted March 11, 2007 whats your problem? is everyone viewing the page or no one? Link to comment https://forums.phpfreaks.com/topic/42242-solved-if-statement/#findComment-204924 Share on other sites More sharing options...
supermerc Posted March 11, 2007 Author Share Posted March 11, 2007 No one can view page Link to comment https://forums.phpfreaks.com/topic/42242-solved-if-statement/#findComment-204933 Share on other sites More sharing options...
Orio Posted March 11, 2007 Share Posted March 11, 2007 Add session_start() in the beginning... Orio. Link to comment https://forums.phpfreaks.com/topic/42242-solved-if-statement/#findComment-204935 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.