i need to update ADMIN COLUMN with $_SESSION variable. however, it does not seem to be working correctly. why? help me plz...

require("conn.php");
$sql = "select * from pemohon where id='$_GET[id]';";
$result = mysql_query($sql);
    while($row = mysql_fetch_array($result))
    {
        $sn = $_SESSION['SESS_NAME'];
        $sql = "update pemohon set admin='$sn',status_key='2' where id='$_GET[id]';";
        $result = mysql_query($sql);
        header("Location: admin.php?page=non_member_1");
    }
}
Member Avatar for iamthwee

Not working correctly

You need to be more specific. What exactly isn't working?

i need to update 'admin' column in database with $_SESSION['SESS_NAME'] value.. but the admin column is blank, can't updated..

Member Avatar for iamthwee

Echo out your variables to the screen before you do you sql.

Check if those variables are what you expect.

echo is working.

Member Avatar for iamthwee

maybe in line 8

$result = mysql_query($sql);

remove the $result and just do:

mysql_query($sql);

actually, status_key column is working, can update with value '2'. but admin column is not working.

Member Avatar for iamthwee

Check $_SESSION['SESS_NAME']; is not empty or contains bad characters.

And that the table name 'admin' is spelt correctly and has the correct upper/lowercase. Judging by what you've written (I've not had a chance to test this) but I would say sess_name is empty or being called wrong.

if i use echo "welcome ".$_SESSION['SESS_NAME']; the output will return welcome DIANA

Member Avatar for iamthwee

Well if you have a value in the admin table equal to 'DIANA' all upper case the only thing left I can think of is that while loop might not be executing once but possibly another time.

To eliminate this as a possibility do this:

    // $sn = $_SESSION['SESS_NAME'];
    $sn = 'DIANA';
    $sql = "update pemohon set admin='$sn',status_key='2' where id='$_GET[id]';";
    $result = mysql_query($sql);
    header("Location: admin.php?page=non_member_1");

^So comment out the first line and run the query again. Does that work?

no, i can't do that, bcoz i need each row updated by different admin.. and admin's name depends on $_SESSION['SESS_NAME']..

Member Avatar for iamthwee

Yes I know that but I just wanted to see if you hardcode it, it actually updates the database.

Just try it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.