Hello,
I am having a problem getting session variables to pass to a page... Basically I set up all my variables, then create a form that submits a username/pass using POST which gets checked against a database. The session is the same as 'authuser'. The weird thing is that it worked fine once. Then I used someone's suggestion of doing the session_destroy() and now it's not working...
Please help.
This is the first part of the file which I believe is the problematic part, but I'm not sure.
<?php
session_start();
$_SESSION['authuser']=$authuser;
$_SESSION['authpass']=$authpass;
$authuser=$_POST['authuser'];
$authpass=$_POST['authpass'];
include("dbinfo.inc.php");
$submit=$_POST['submit'];
$sort=$_GET['sort'];
$order=$_GET['order'];
if(!$order){
$order="ASC";
}
if(!$sort){
$sort="firstname";
}
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM contest ORDER BY $sort $order";
$result=mysql_query($query);
$num=mysql_numrows($result);
$querypass="SELECT * FROM passwords WHERE authuser='$authuser' AND authpass='$authpass'";
$resultpass=mysql_query($querypass);
$numpass=mysql_num_rows($resultpass);
mysql_close();
?>
Then I start in with the if/elseif commands
the first if
<? if($numpass=="1"){?>
<? session_start();
echo "".session_id()."";
?>
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
</tr>
<tr>
<td valign="top"><br>
<div align="center" class="style1"><span class="style2">Current List</span><br>
<br>
</div></td>
</tr>
<tr>
<td valign="top">
<form name="form1" method="GET" action="contest_results.php">
<select name="sort" size="1">
<option value="">Select
<option value="firstname">First Name
<option value="lastname">Last Name
<option value="email">E-Mail
<option value="age">Age
</select>
<input name="Submit" type="submit" class="redform" value="Order List">
</form>
<div align="center"><a href="logout.php">Logout</a></div>
</td>
</tr>
<tr>
<td valign="top"><? echo " Sorting by $sort. <a href=\"contest_results.php?sort=$sort&order=ASC\"><img src=\"../graphics/nav_buttons/up_cc0000.gif\" width=\"5\" height=\"5\" border=0></a> <a href=\"contest_results.php?sort=$sort&order=DESC\"><img src=\"../graphics/nav_buttons/down_cc0000.gif\" width=\"5\" height=\"5\" border=0></a>"?></td>
</tr>
<tr>
<td valign="bottom">
<img src="../graphics/bkgd/1px_333.gif" width="100%" height="5"></td>
</tr>
<td>
<table align="left" width="350" border="0" cellspacing="0" cellpadding="0">
<?
$i=0;
while ($i < $num) {
$name=mysql_result($result,$i,"firstname");
$namelast=mysql_result($result,$i,"lastname");
$address_1=mysql_result($result,$i,"address_1");
$city=mysql_result($result,$i,"city");
$state=mysql_result($result,$i,"state");
$country=mysql_result($result,$i,"country");
$phone=mysql_result($result,$i,"phone_number");
$email=mysql_result($result,$i,"email");
$zip=mysql_result($result,$i,"zip");
$age=mysql_result($result,$i,"age");
$comments=mysql_result($result,$i,"comments");
?>
<tr>
<td rowspan="3" background="../graphics/bkgd/1px_333.gif"><img src="../graphics/bkgd/1px_trans.gif" width="10" height="100%"></td>
<td><img src="../graphics/bkgd/1px_333.gif" width="100%" height="5"></td>
<td rowspan="3" background="../graphics/bkgd/1px_333.gif"><img src="../graphics/bkgd/1px_trans.gif" width="10" height="100%"></td>
</tr>
<tr>
<td width="330" bgcolor="#666666">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td><?php echo "$name $namelast - ";
if(!$age){
echo "Did not give age information.<br>";
}
else{
echo "$age years old.<br>";
}
echo "$address_1<br>$city, $state $zip<br>$phone<br><a href=\"mailto:$email\">$email</a>"?></td>
</tr>
<tr><td>
<? echo"<div class=\"whitetiny\"><strong>Comments</strong></div>$comments" ?>
</td>
</tr>
</table></td>
</tr>
<tr>
<td>
<img src="../graphics/bkgd/1px_333.gif" width="100%" height="5"></td>
</tr>
<?
++$i;
}
?>
</table>
</td>
</tr>
</table>
<br>
Then I have a user/pass form that gets submitted if the user/pass variables have not been assigned:
<? }
elseif(!$authuser || !$authpass){?>
<br><br><br>
<form name="form2" method="POST" action="contest_results.php"><table width="350" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#666666">
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td width="50%">
<div align="right">Username</div></td>
<td><input name="authuser" type="text" id="authuser" size="23" maxlength="23"></td>
</tr>
<tr>
<td colspan="2"><img src="../graphics/bkgd/1px_trans.gif" width="100%" height="5"></td>
</tr>
<tr>
<td><div align="right">Password</div></td>
<td><input name="authpass" type="password" id="authpass" size="25" maxlength="25"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input name="Submit" type="submit" class="redform" value="Submit">
<input name="Reset" type="reset" class="redform" value="Reset">
<img src="../graphics/bkgd/1px_trans.gif" width="100%" height="5"> </div></td>
</tr>
</table>
</form>
Then I have an elseif in case the user/pass combo was incorrect.
<? }
elseif($numpass=="0"){?>
<br><br><br>
<form name="form2" method="POST" action="contest_results.php">
<table width="350" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#666666">
<tr>
<td colspan="2">Something was entered incorrectly... </td>
</tr>
<tr>
<td width="50%"><div align="right">Username</div></td>
<td><input name="authuser" type="text" id="authuser" size="23" maxlength="23"></td>
</tr>
<tr>
<td colspan="2"><img src="../graphics/bkgd/1px_trans.gif" width="100%" height="5"></td>
</tr>
<tr>
<td><div align="right">Password</div></td>
<td><input name="authpass" type="password" id="authpass" size="25" maxlength="25"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input name="Submit" type="submit" class="redform" value="Submit">
<input name="Reset" type="reset" class="redform" value="Reset">
<img src="../graphics/bkgd/1px_trans.gif" width="100%" height="5"> </div></td>
</tr>
</table>
</form>
Then I have a default for every other outcome...
<? }
else{?>
<br><br><br>
<form name="form2" method="POST" action="contest_results.php">
<table width="350" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#666666">
<tr>
<td width="50%" height="26"><div align="right">Username</div></td>
<td><input name="authuser" type="text" id="authuser" size="23" maxlength="23"></td>
</tr>
<tr>
<td colspan="2"><img src="../graphics/bkgd/1px_trans.gif" width="100%" height="5"></td>
</tr>
<tr>
<td><div align="right">Password</div></td>
<td><input name="authpass" type="password" id="authpass" size="25" maxlength="25"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input name="Submit" type="submit" class="redform" value="Submit">
<input name="Reset" type="reset" class="redform" value="Reset">
<img src="../graphics/bkgd/1px_trans.gif" width="100%" height="5"> </div></td>
</tr>
</table>
</form><? }
?>