Solved

Help With Cookies

Posted on 2004-04-11
3
201 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
Comment Utility
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
Comment Utility
Thanks alot man i really appreciate your help. You deserve an A :-D
0
 
LVL 5

Expert Comment

by:crazycomputers
Comment Utility
You're welcome, and thanks!  =)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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 dynamically set the form action using jQuery.

771 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

12 Experts available now in Live!

Get 1:1 Help Now