Login script that isn't working

Alright here is part of what is in the index.php:
                        <?
               if ($logged == 'yes')
               {
               print_loggedin();
               }
               else
               {
               print_normal();
               }
               function print_normal()
               {
               echo "<h1>Login</h1>";
         
                    echo "<form action=\"login.php\" method=\"post\">";
          echo "User: <input type=\"text\" maxlength=\"12\" size=\"12\" name=\"username\"><br />";
          echo "Pass: <input type=\"password\" maxlength=\"15\" size=\"12\" name=\"password\"><br />";
          echo "<input type=\"hidden\" name=\"logmein\" value=\"1\">";
          echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
          echo "<input type=\"submit\" name=\"Login\" value=\"Login\"></form>";
          echo "<center><a href=\"index.php?action=register\">Sign Up!  </a><a href =\"lostpass.php\">Lost Password?</a></center>";
               echo "</div>";
               echo "<p>";
               echo "</p>";
               }
               
               function print_loggedin()
               { // and here comes the Ecom information
          echo "<h1>User Controls</h1>";
          echo "Hello $username";
          echo "<br>";
          echo "Currently you have: $cartHowMany"; // still needs to be made
          echo "Itmes on your shopping cart.";
          echo "You current balance is: $balance"; // still needs to be made
          echo "<a href=\"control.php\">Control Panel</a> <a href=\"index.php?action=logout\">Log Out</a>";
          }
               ?>

thats all the table functions and what not to change the tables.

and here is the login.php:
<?php
if ($submit = "Login")
{
  mysql_connect("localhost", "*****", "*****") or                
    die ("Could not connect to database");

  mysql_select_db("account") or
    die      ("Could not select database");  

$result=mysql_query("select * from users where username='$username'")
             or die ("cant do it");

while ($row=mysql_fetch_array($result)) {
 if ($row["password"]==$password )
  {
     setcookie("logged","yes",time()+3600);
     setcookie("username","$username",time()+3600);
     echo "<script language=\"javascript\">";
     echo "var jumpURL = \"javascript:history.go(-1)\";";
    echo "function jumpBack() {";
    echo "window.location = jumpURL;";
     echo "}";
     echo "setTimeout(\"jumpBack()\", 3000);";
     echo "</SCRIPT>";
  }
  else
      {
     echo "<script language=\"javascript\">";
     echo "var jumpURL = \"javascript:history.go(-1)\";";
    echo "function jumpBack() {";
    echo "window.location = jumpURL;";
     echo "}";
     echo "setTimeout(\"jumpBack()\", 3000);";
     echo "</SCRIPT>";
    print("Password incorrect!");
   
   }
 }
}
?>


alright so what it is supposed to do is if the username and password watch is set a cookie so that it shows that 'logged' is set to yes and everything, and then go back to the index.php and have the tables changed so it shows what you currently have on your "cart" and what not, just wondering why it is not doing this, the cookie is not being set for some reason anyone see any area's that theres an error in? Thanks.
DlAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

carchitectCommented:
if ($submit = "Login")

sorry it is

if ($submit = "Login")

0
carchitectCommented:
if ($submit = "Login")

sorry it is

if ($submit == "Login")

0
titaniumslugCommented:
umm, the fuctions print_loggedin and print_normal should be placed on the above print_loggedin(); and print_normal();
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

DlAuthor Commented:
Alright I made those changes, but its still not working, and the cookies are still not bein set :/
0
DlAuthor Commented:
Alright I made those changes, but its still not working, and the cookies are still not bein set :/
0
DlAuthor Commented:
hm sry about double post ... not sure why that happend
0
DlAuthor Commented:
Any body see any reason for this not to work..? Anyone at all?
0
JoeisanerdCommented:
Are you using Windows version of PHP? Check your php.ini file to make that globals are turned on.  Also I assume you are calling the session_start() and session_register() for those variables?
0
titaniumslugCommented:
do you get a header error? setcookie() must always be right on top, before everything else.
you could set it to transfer the user to another page which will set the cookies after "if ($row["password"]==$password )"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DlAuthor Commented:
Thanks alot, I ended up putting the setcookie()'s into the top of another script. Now goes index > login > login2 > index. Thanks alot.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.