Solved

Help With Cookies

Posted on 2004-04-11
3
204 Views
Last Modified: 2008-02-20
hello i am new to php and i am making a login system using php but i am getting problems with it.
For example when you login it checks if a person has that name and password and if its true then :

        setcookie("user",$username);
        setcookie("pass",$password);
        header("location:console.php");

Ok then in the console.php it shows your profile like your username and email and msn:
Username: farhadabas
MSN: blahblah@hotmail.com

 Well then i have change profile link when you click it takes you to ch_profile.php. There you can change your info in the text boxes and stuff then when you click submit it sends this to chprofile.php. There it takes the info that you sent and updates the database with your new info. After it does that i want it to update the old cookie so it has the new username in it since you changed it. So i just put:      
 
 setcookie("user",'$_POST[username]');

username is the textbox name from the previous change profile page.

And after that  i have:

header("location:console.php");

Well when it goes to console.php again all the fields are empty for some reason. Like it says

Username: ________
MSN: _____________

but it should not be empty tho.

Oh yea and this is how it gets the info for your profile out of database in colsole.php:  

    $conn = mysql_connect($sql_host, $sql_username);
      mysql_select_db("$sql_database",$conn);
      $sql="SELECT * FROM members where username='$_COOKIE[user]' and password= '$_COOKIE[pass]'";
      $result = mysql_query($sql, $conn) or die(mysql_error());

      while ($newArray = mysql_fetch_array($result)) {

         $password  = $newArray['password'];
         $username = $newArray['username'];
         $msn = $newArray['msn'];
         $email = $newArray['email'];

Can someone tell me how to fix it so when you click submit and after it updates the cookie that in the console your profile info is not empty?

Help REALLY APPRECIATED
0
Comment
Question by:farhadabas
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
crazycomputers earned 250 total points
ID: 10801395
This line is incorrect:

setcookie("user",'$_POST[username]');

You are setting the user cookie to the value "$_POST[username]", NOT what is contained in it.  Remove the single quotes and try again:

setcookie("user",$_POST['username']);

You are probably not seeing anything because (according to the MySQL code above) the code doesn't do anything if the user doesn't exist.  And I venture to guess that you don't have a user named "$_POST[username]".

And a side note: that code WOULD work if you had used double-quotes instead of single quotes as well.  Using no quotes is a bit cleaner and faster if nothing besides a single variable is being used.
0
 

Author Comment

by:farhadabas
ID: 10801423
Thanks alot man i really appreciate your help. You deserve an A :-D
0
 
LVL 5

Expert Comment

by:crazycomputers
ID: 10801634
You're welcome, and thanks!  =)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question