?
Solved

Help With Cookies

Posted on 2004-04-11
3
Medium Priority
?
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
crazycomputers earned 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

777 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