Jump to content

error check - driving me crazy


matthew798

Recommended Posts

Hey guys! The error is that it seems to display EVERYTHING regardless of the if and else statements. Also, it seems to stop evaluating the rest of the document that "includes" this as soon as its done with this one. dbconnect works and all the session vars carry properly... WTF is going on!?

<?php
session_start();
include 'dbconnect.php';

$username = $_SESSION['username'];

$q = mysql_query("SELECT User_type FROM account WHERE username = '$username'")
or die(mysql_error());

$permission = mysql_fetch_row($q);
$permission = $permission[0];

if(isset($_SESSION['username']) && $permission >= 2){

       echo"<div id='page-section-mainmenu'><ul><li><a href=''><span>";
   echo $menu001;
   echo "</span></a></li><li><a href=''><span>";
   echo $menu002;
   echo "</span></a></li><li><a href=''><span>";
   echo $menu003;
   echo "</span></a></li><li><a href=''><span>";
   echo $menu004;
   echo "</span></a></li><li><a href=''><span>";
   echo $menu006;
   echo "</span></a></li>";}
   
   elseif($permission <= 1){ 
	   echo"<div id='page-section-mainmenu'><ul><li><a href=''><span>";
	   echo $menu001;
	   echo "</span></a></li><li><a href=''><span>";
	   echo $menu002;
	   echo "</span></a></li><li><a href=''><span>";
	   echo $menu003;
	   echo "</span></a></li><li><a href=''><span>";
	   echo $menu004;
	   echo "</span></a></li>";}

else{
       echo"<div id='page-section-mainmenu'><ul><li><a href=''><span>";
   echo $menu001;
   echo "</span></a></li><li><a href=''><span>";
   echo $menu002;
   echo "</span></a></li><li><a href=''><span>";
   echo $menu003;
   echo "</span></a></li><li><a href=''><span>";
   echo $menu005;
   echo "</span></a></li>";
   
   echo "<span>
   <form action='login.php' method='POST'>
   
	<input type='text' value='username' name='username'>
	<input type='text' value='password' name='password'>


	<input type='submit'>

	</form>

   </span>
   			</li>
          </ul>
        </div>
      </div>";}

  ?>

Link to comment
https://forums.phpfreaks.com/topic/212399-error-check-driving-me-crazy/
Share on other sites

isset() evaluates to on empty values such as '' or 0 or array(), could that be an issue?  Also note that the elseif, because it doesn't check $_SESSION['username'], can succeed even if $_SESSION['username'] is not set.  This would be clearer if it was not indented.

 

As for debugging why it stops execution, I would add some diagnostic print statements.  I often use a line like print "hello";, and I move the line around, checking whether that piece of code gets executed.  After a few tries I can narrow down the exact point that execution stops.

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.