Hi guys
I have a session that holds my user's user_name, user_level, and some other info, and echo it on every page. But I have a problem when my Admin user changes another user's information in a form on my edit user page.
Once the form submits, my $_SESSION['user_name'] gets lost.
I know it's lots of code, but I want you to see my process.
I have left out the html href="stylesheet.css" and all that for easier reading.
Might be an obvious answer to my problem, but why do I loose this session?
<?
session_start();
include "../config.php";
if(isset($_POST['Amend'])) {
$user_pass = md5($_POST[user_pass]);
$user_email = $_POST['user_email'];
$user_tel = $_POST['user_tel'];
if(empty($_POST['user_pass']))
{
$result = mysql_query("Update login_table set user_email='$user_email', user_tel='$user_tel' where userid=".$_POST['userid']);
}
else
{
$result = mysql_query("Update login_table set user_pass='$user_pass', user_email='$user_email', user_tel='$user_tel' where userid=".$_POST['userid']);
}
$msg = "User updated<br>";
$edit = "";
}
if ($order == "") {$order = "userid";}
$result = mysql_query("Select * from login_table WHERE com_usercode='".$_SESSION['com_usercode']."' ORDER BY '$order'",$con);
$num = mysql_num_rows($result);
$n = 0;
?>
<div id="colTwo">
<ul>
<li>
Your Detail
<ul>
<li>
<font size="1">
<? echo "Username<ul><strong><font color=\"#000000\" size=\"2\">".$_SESSION['user_name']."</font></strong></ul>"; ?>
<? echo "Login Level<ul><strong><font color=\"#000000\" size=\"2\">".$_SESSION['level']."</font></strong></ul>"; ?>
<? echo "Company Code<ul><strong><font color=\"#000000\" size=\"2\">".$_SESSION['com_usercode']."</font></strong></ul>"; ?>
<? echo "E-Mail Address<ul><strong><font color=\"#000000\" size=\"2\">".$_SESSION['user_email']."</font></strong></ul>"; ?>
<? echo "Registered Date<ul><strong><font color=\"#000000\" size=\"2\">".$_SESSION['user_date']."</font></strong></ul>"; ?>
<a href="../search.php">Search</a>
</font>
</li>
</ul>
</li>
</ul>
</div>
User Information
<table width="100%" border="0">
<tr>
<td width="5%"><a href="users.php?order=userid">ID</a></td>
<td width="16%"><a href="users.php?order=user_name">User Name</a></td>
<td width="8%"><a href="users.php?order=user_level">Level</a></td>
<td width="18%"><a href="users.php?order=user_email">E-Mail</a></td>
<td width="17%"><a href="users.php?order=user_tel">Tel</a></td>
<td width="14%"><a href="users.php?order=user_ip">User IP</a></td>
<td width="22%"><a href="users.php?order=date">Date Registered</a></td>
</tr>
<?php while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
$n++;
?>
<tr>
<td width="5%"><?php echo $row['userid'];?></td>
<td width="16%">
<?php
if($row['userid'] > "1")
{
?>
<a href="users.php?edit=<? echo $row['userid']?>"><? echo $row['user_name']; ?></a>
<?
}
else
{
echo $row['user_name'];
}
?>
</td>
<td width="8%"><?php echo $row['user_level'];?></td>
<td width="18%"><?php echo $row['user_email'];?></td>
<td width="17%"><?php echo $row['user_tel'];?></td>
<td width="14%"><?php echo $row['user_ip'];?></td>
<td width="22%"><?php echo $row['date'];?></td>
</tr>
<?php
}
?>
</table>
<?php
if ($edit)
{
$msg = "Edit record below";
if ($edit == "admin")
{
$msg = "You cannot edit Admin";
exit ();
}
$result = mysql_query("Select * from login_table WHERE userid = '$edit'",$con);
$row = mysql_fetch_array($result);
?>
<br />
<br />
<form name="form2" method="post" action="">
Edit User:
<table width="101%">
<tr>
<td width="11%">User Name</td>
<td width="23%">Password</td>
<td width="22%">E-Mail</td>
<td width="20%">Tel</td>
</tr>
<tr>
<td><strong><?php echo $row['user_name'];?></strong></td>
<td><input type="user_pass" name="user_pass" value=""></td>
<td><input type="user_email" name="user_email" value="<?php echo $row['user_email']; ?>"></td>
<td><input type="user_tel" name="user_tel" value="<?php echo $row['user_tel']; ?>"></td>
</tr>
</table>
<input type="hidden" name="userid" value="<?php echo $row['userid'];?>">
<input type="Submit" name="Amend" value="Update">
</form>
<?php
}
?>
I've also tried to do this in the beginning:
$adminuser = $_SESSION['user_name'];
Then replacing all $_SESSION['user_name'] with $adminuser.
I couldn't find any thing on Session that gets lost through forms.
Thanks