troubleshooting Question

Undefined variable - register globals set off

Avatar of Refael
RefaelFlag for United States of America asked on
PHP
9 Comments2 Solutions331 ViewsLast Modified:
As a PHP fresh pioneer :-) I am following some of the online video tutorials
I came to a point where a page scripts works fine in the tutorial but once I try them on my local machine I always get the Undefined variable NOTICE. My register globals is set to OFF because as it says in the PHP.ini "You should do your best to write your scripts…." So I do not want to turn it off. But still, how can I pass this. I tried to declare the variables at the beginning of the script and still am getting the same notice and the script does not work/process. Here is an example I did for a login page:

<? session_start()?>
<html>
<body>
<?
if ($user && $pass) {
       if ($logged_in_user == $user) {
             echo $user.", You are already logged in";
             echo $link;
             exit;
       }
      $conn = mysql_connect("localhost", "root", "pass");
       mysql_select_db("userlist", $conn);
       $result = mysql_query("SELECT * FROM users WHERE name='".$user."'
                              AND password = PASSWORD ('".$pass."')");
   
       if (!$result){
             echo "Sorry, there has been a technical hitch. We cannot enter your data";
             exit;
       }
 // if there are results
 if (mysql_num_rows($result)>0) {
       $logged_in_user = $user;
       // input into session
       session_register("logged_in_user");
       // output seesion
       echo "Welcome ".$logged_in_user.".<br><br>";
       echo $link;
       exit;
       
    } else {
               echo "Invalid login. Please try again";
    }
                     
    } else if ($user || $pass){
      echo "Please fill in both fields";
}

?>

<form action="login.php" method="POST">
UserName: <input type="text" name="user" maxlength="20" size="20"><br>
Password: <input type="password" name="pass" maxlength="10" size="20"><br>
<input type="submit" value="Login">
</form>

</body>
</html>
ASKER CERTIFIED SOLUTION
daveaton

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros