View Full Version : session problems....

03-13-2007, 01:39 PM
i have a problem where i can only update the first name in my database details no matter whose logged in.here is the code.Any suggestions?

First part of the code
case 'detail':

echo '<p>
Please enter your details below.</p>
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<input name="price" type="text" class="textBox"></p>
<input name="area" type="text" class="textBox"></p>
<input name="description" type="text" class="textBox"></p>
<p><input type="submit" value="Edit Details" name="editdetail"></p>


second part:
$username = $_SESSION['username'];
$price = trim($_POST['price']);
$area = trim($_POST['area']);
$description = trim($_POST['description']);
$do = mysql_query("UPDATE Users SET price = '$price' WHERE username='$username' LIMIT 1") or die(mysql_error());
$dotwo = mysql_query("UPDATE Users SET area = '$area' WHERE username='$username' LIMIT 1") or die(mysql_error());
$dothree = mysql_query("UPDATE Users SET description = '$description' WHERE username='$username' LIMIT 1") or die(mysql_error());

03-13-2007, 10:37 PM
Are you starting the session (http://us2.php.net/session_start)?

03-14-2007, 12:34 PM
yes the session has been started this is the code i used.
if($_SESSION['s_logged_n'] == 'true'){
include 'process.php';

03-14-2007, 05:08 PM
OK... have you made sure your $username variable is set properly-- that is to say, it contains the value you expect it to contain? Don't assume this is true-- add an echo statement to make sure it is true.

03-15-2007, 10:08 AM
so where do i put the echo statement ?

03-15-2007, 03:32 PM
And try this too (the correct way to use the if statement with your session) ...

include 'process.php';


03-15-2007, 05:35 PM
I can't say for sure, because I never really think when I'm coding...it just flows naturally..but I once remembered something about similar name conflicts..
For example,
$username and $_SESSION["username"]

Try using different variable names..

I'm not entirely sure of this fixes your problem, but I am definitely sure there's a conflict problem between one of these types, such as $_SESSION["username"], and $_GET["username"] ...

Part and parcel of programming. Logic alone isn't sufficient to get you to the top.


03-15-2007, 05:39 PM
SpinCode ...

You are correct ... I just went through that problem myself.

What occurred with me was similar. I had used "$user" as a session variable,
and also had a PHP email client that used the same variable for a session.
It sort of locked things up with the PHP email client. It took me a while to
figure out what was happening.

Once I changed the session variable on my admin page to "$aduser", it all
fell into place and worked fine.

03-15-2007, 10:13 PM
I hate the whole register_globals idea and this is a really good reason why it should die.