Forum Moderators: coopster
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
$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);
;?>
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?
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!