Solved

Help With Cookies

Posted on 2004-04-11
3
202 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
wamp versus xampp 4 46
<? versus <?php 5 37
I am Updating mysql where id =something ...Not working  Jquery/PHP 4 39
PHP get array item with custom id 4 24
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now