Forum Moderators: coopster

Message Too Old, No Replies

update page works on everything but username!

         

nshack31

1:46 pm on Jan 5, 2005 (gmt 0)

10+ Year Member



hi i store the username in a cookie $_COOKIE[username] I have an update page which displays the users details and allows them to update them. The page allows you to update all fields but the username will not update!...

First i store the cookie in a variable
$me=$_COOKIE['username'];

then my sql statement is ..

$sql="UPDATE users SET username = '$username', password = '$pass', clanname = '$clanname', email = '$email', clanweb = '$clanweb', clanshorttag = '$clanshorttag' , clanslogan = '$clanslogan', clanrule = '$clanrule', clanvoipaddress = '$clanvoipaddress', clanvoippassword = '$clanvoippassword', clanvoipdescription = '$clanvoipdescription' WHERE username = '$me'";

I then inculde this...

setcookie ("username", "",time()-3600);
setcookie ("username", $username,time()+3600);
header ('location: clanadmin.php');

This should set the new username in the cookie and redirects the user.

The update works fine on all the fields apart from the username one. Obviously i extract the username from the cookie because the $username posted from the form will differ from that in the DB.

Can anyone help!?! thankyou

mcibor

1:58 pm on Jan 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try debugging the script by printing out the $sql

print("Sql question: $sql<br>");

and see if this is the username that you require.
The question works fine in mySQL, so the problem must lay in the PHP, or cookie.

Print out all username variables and see if they are correct.

nshack31

2:06 pm on Jan 5, 2005 (gmt 0)

10+ Year Member



I changed my code to use and ID..

$sql="UPDATE users SET username = '$username', password = '$pass', clanname = '$clanname', email = '$email', clanweb = '$clanweb', clanshorttag = '$clanshorttag' , clanslogan = '$clanslogan', clanrule = '$clanrule', clanvoipaddress = '$clanvoipaddress', clanvoippassword = '$clanvoippassword', clanvoipdescription = '$clanvoipdescription' WHERE id = $id";

so now there is no reason for all fields except username to update! The reason the username field will not update is something to do with the cookie, yet i cant figure it out! :(

If I edit the code to delete the cookie after the SQL statement then it correctly tells me to login again!
So its something to do with the setcookie("username", $username,time()+3600); part

Edit.. Here is my code with the problem part highlighted

<?php
$id=($_REQUEST['id']);
$conn=odbc_connect('league','','');
if( get_magic_quotes_gpc() ) {
$username=stripslashes($_REQUEST['username']);
$pass=stripslashes($_REQUEST['password']);
$clanname=stripslashes($_REQUEST['clanname']);
$email=stripslashes($_REQUEST['email']);
$clanweb=stripslashes($_REQUEST['clanweb']);
$clanshorttag=stripslashes($_REQUEST['clanshorttag']);
$clanslogan=stripslashes($_REQUEST['clanslogan']);
$clanrule=stripslashes($_REQUEST['clanrule']);
$clanvoipaddress=stripslashes($_REQUEST['clanvoipaddress']);
$clanvoippassword=stripslashes($_REQUEST['clanvoippassword']);
$clanvoipdescription=stripslashes($_REQUEST['clanvoipdescription']);
$username = str_replace( "'", "''", $username );
$pass = str_replace( "'", "''", $pass );
$clanname = str_replace( "'", "''", $clanname );
$email = str_replace( "'", "''", $email );
$clanweb = str_replace( "'", "''", $clanweb );
$clanshorttag = str_replace( "'", "''", $clanshorttag );
$clanslogan = str_replace( "'", "''", $clanslogan );
$clanvoipaddress = str_replace( "'", "''", $clanvoipaddress );
$clanvoippassword = str_replace( "'", "''", $clanvoippassword );
$clanvoipdescription = str_replace( "'", "''", $clanvoipdescription );
}
if (!$conn)
{
exit(
"Connection Failed: " . $conn);
}
$sql="UPDATE users SET username = '$username', password = '$pass', clanname = '$clanname', email = '$email', clanweb = '$clanweb', clanshorttag = '$clanshorttag' , clanslogan = '$clanslogan', clanrule = '$clanrule', clanvoipaddress = '$clanvoipaddress', clanvoippassword = '$clanvoippassword', clanvoipdescription = '$clanvoipdescription' WHERE id = $id";

$rs=odbc_exec($conn,$sql);

if (!$rs)
{
exit("Error in SQL");
}
else
{
setcookie ("username", "",time()-3600);
setcookie ("username", $username,time()+3600);
header ('location: clandetails.php');
}

odbc_close($conn);
;?>

nshack31

2:13 pm on Jan 5, 2005 (gmt 0)

10+ Year Member



ok where it previously said..

setcookie ("username", "",time()-3600);
setcookie ("username", $username,time()+3600);
header ('location: clanadmin.php');

I replaced it with

echo "($username)";

The username that is echoed is not the updated one! Why is it the old username, despite $username coming from the form?

nshack31

2:30 pm on Jan 5, 2005 (gmt 0)

10+ Year Member



sorted! had to rename cookie to username1!

mcibor

10:45 pm on Jan 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If that was the solution, then the problem was in $_REQUEST[]

It must have taken the value from the $_COOKIE, not the $_POST. If you have been using $_POST or $_GET to get value, none of this would have happened.

The mySQL question below is correct:

UPDATE table SET v = '5' WHERE v = '1';

No problem with that, however it looks horrible :D

See you soon!