session problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

sorry... :(

Code: Select all

<?
session_start();
?>
<html>
<head>
<title>template</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="templates/site.css" type="text/css">
</head>

<body bgcolor="#E5E5E5" topmargin="5" leftmargin="5" rightmargin="5" bottommargin="5">
<div align="center">
<table width="100%" height="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#999999" bgcolor="#FFFFFF">
  <tr valign="top">
      <td> <table width="100%" height="150" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td>&nbsp;</td>
          </tr>
          <tr> 
            <td height="50">
				<table width="300" height="50" align="center">
				<tr>
					<td>
					<?
					//start of submit conditions
					if (isset($_POST&#1111;'submit']))
					&#123;
						require_once('dbconnect.php');
	
						$message = NULL;
	
						$message = NULL;
						
						//verify username
						if (empty($_POST&#1111;'username'])) 
						&#123;
							$un = FALSE;
							$message .= 'Please enter your username!<br>';
						&#125; 
						else 
						&#123;
							$un = stripslashes($_POST&#1111;'username']);
						&#125;
						
						//verify password
						if (empty($_POST&#1111;'password'])) 
						&#123;
							$pw = FALSE;
							$message .= 'Please enter your password!<br>';
						&#125; 
						else 
						&#123;
							$pw = stripslashes($_POST&#1111;'password']);
						&#125;
						
						//if username and password OK...
						if ($un && $pw) 
						&#123;
							$query = "SELECT userID, firstname, lastname FROM users WHERE username='$un' AND password='$pw'";		
							$result = @mysql_query ($query);
							$row = mysql_fetch_array ($result, MYSQL_NUM); 
							if ($row) 
							&#123; 								
								$_SESSION&#1111;'lastname'] = $row&#1111;2];									
								$_SESSION&#1111;'firstname'] = $row&#1111;1];
								$_SESSION&#1111;'userID'] = $row&#1111;0];
								header ("Location:  http://" . $_SERVER&#1111;'HTTP_HOST'] . dirname($_SERVER&#1111;'PHP_SELF']) . "/index.php");
								exit();				
							&#125; 
							else 
							&#123;
								$message = 'The username and password entered do not match.<br>'; 
							&#125;
						mysql_close();
						&#125; 
						else 
						&#123;
							$message .= 'Try again.<br>';		
						&#125;
					&#125;//end of submit conditions

					if (isset($message))
					&#123;
						echo '<font color="red">', $message, '</font>';
					&#125;
					?>
					</td>
				</tr>
				</table>
			</td>
          </tr>
        </table> 
        <table width="100%" height="200" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><table width="300" height="200" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="336699">
                <tr>
                  <td><table width="100%" height="20" border="0" align="center" cellpadding="0" cellspacing="0">
                      <tr>
                        <td>&nbsp;</td>
                      </tr>
                    </table>
                    <table width="298" height="160" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="ffffff">
                      <tr>
                        <td> 
                          <!--start-->
						 <table width="100%" align="center" bgcolor="#ffffff">
						<form action="<? $_SERVER&#1111;'PHP_SELF']; ?>" method="post">
						<tr>
							<td width="30%"><b>username:</b></td>
							<td width="70%"><input type="text" name="username" value="<? if (isset($_POST&#1111;'username'])) echo $_POST&#1111;'username']; ?>"></td>
						</tr>
						<tr>
							<td width="30%"><b>password:</b></td>
							<td width="70%"><input type="password" name="password" value="<? if (isset($_POST&#1111;'password'])) echo $_POST&#1111;'password']; ?>"></td>
						</tr>
						<tr>
							<td width="30%"></td>
							<td width="70%">
								<table width="100%" bgcolor="#ffffff" cellpadding="0" cellspacing="0">
								<tr bordercolor="#ffffff">
									<td width="30%"><input type="submit" name="submit" value="login"></td>
									<td width="40%"><p align="right"><b><a href="register.php" class="under">register</a></b></p></td>
									<td width="30%"></td>
								</tr>
								</table>			
							</td>
						</tr>
						</form>
						</table>
						
						<!--end-->
						</td>
                      </tr>
                    </table>
                    <table width="100%" height="20" border="0" cellpadding="0" cellspacing="0">
                      <tr>
                        <td>&nbsp;</td>
                      </tr>
                    </table></td>
                </tr>
              </table></td>
          </tr>
        </table></td>
  </tr>
</table>
</div>
</body>
</html>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the script doesn't attempt to set $_SESSION['company'] .... if index.php is referencing it, obviously nothing will show for it.
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

oops!!sori, i forgot to add the company session, here i'll add it in the code below:

Code: Select all

if ($un && $pw) 
&#123;
$query = "SELECT userID, firstname, lastname FROM users WHERE username='$un' AND password='$pw'";		
$result = @mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_NUM); 
if ($row) 
&#123;
 $_SESSION&#1111;'company'] = $row&#1111;3];							
$_SESSION&#1111;'lastname'] = $row&#1111;2];									
$_SESSION&#1111;'firstname'] = $row&#1111;1];
$_SESSION&#1111;'userID'] = $row&#1111;0];
header ("Location:  http://" . $_SERVER&#1111;'HTTP_HOST'] . dirname($_SERVER&#1111;'PHP_SELF']) . "/index.php");
exit();				
&#125; 
else 
&#123;
$message = 'The username and password entered do not match.<br>'; 
&#125;
when i attempted to call the $_SESSION['company'] = $row[3]; it returned nothing to the index page.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

'company' isn't in the query.
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

oh yah....i got it now..thanks a lot....it slipped my eyes, thanks, thanks very much :lol: :lol: :lol:
Post Reply