SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,891
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Help Fixng Errors Please

    Hello,
    Below are the errors I am getting:

    Notice: Undefined index: action in D:\wamp\www\template atm\membership.php on line 33

    Notice: Undefined index: loggedin in D:\wamp\www\template atm\membership.php on line 36

    Notice: Undefined index: action in D:\wamp\www\template atm\membership.php on line 78

    Notice: Undefined index: action in D:\wamp\www\template atm\membership.php on line 153

    Notice: Undefined index: action in D:\wamp\www\template atm\membership.php on line 242

    Now is the code of the entire page:

    PHP Code:
    <?php
    $pagetitle 
    'Membership System';
    include (
    'template/templatetop.php');

    ################################################# - EXTRA PHP CODE - ####################################################

    ################################################# - END EXTRA PHP CODE - ####################################################



    ?>
    <!--################################################# - START PAGE CONTENT - ####################################################-->

    <?php 

    //error_reporting(0);

    //$_SESSION['loggedin'] = 0;
    //$_SESSION['username'] = 'tester';

    ?>

    <!--Code for every membership page-->

    <img src="img/small_graphics/memshipcard.png" alt="Alton Towers Mania membership System" /><br />

    <!--End code for every membership page-->



    <?php
    //If no action is set and a user is not logged in then show defult page state.
    if ($_GET['action'] == "")


        if (
    $_SESSION['loggedin'] == 0){

    ?>

            <!--Intro Text--> 
            <p>Welcome to the Alton Towers Mania Membership System. Registering as part of the membership system will allow you to be more integrated with the site and give you access to do more exciting features, like submitting your high score on Duel to the high score board to tracking what rides you have ridden as well as which are your favourite rides at the park! The Duel Score board and favourites are coming very very soon! Please note that your Forum Community membership account is not the same as your membership account for this system.</p>
            <!--End Intro Text-->

            <!--New Lines-->
                <br /><br />
            <!--End New Lines-->

            <p class="center mediumheadings"><a href="membership.php?action=login&mode=new">Log In</a>&nbsp;&nbsp;&nbsp;: :&nbsp;&nbsp;&nbsp;<a href="membership.php?action=register&mode=new">Register</a></p>

    <?php
        

        else 
        {
        
    //If a user is logged in then show logged in page state
    ?>

            <!--Intro Text--> 
            <p>Welcome to the Alton Towers Mania Membership System. Now you have logged in you can visit the various links below to access different parts of the site which support the membership system. Any areas of this site where you see the membership system icon, allow you to use your account with them. You can log out of the membership system at anytime using the "Log Out" link to the left.</p>
            <!--End Intro Text-->

            <!--New Lines-->
                <br /><br />
            <!--End New Lines-->

            <ul>
                <li><a href="ridetracker.php">Ride Tracker</a></li>
                <li><!--<a href="favouriterides.php">-->Favourites</a></li>
                <li><!--<a href="duelboard.php">-->Duel Score Board</a></li>
            </ul>

    <?php

        
    }


    //NEXT SECTION
    //If the action is "login" and the loggedin session already equals 1 then display the already logged in message.
    if ($_GET['action'] == "login" )
    {
     
        if (
    $_SESSION['loggedin'] == 1
        {

    ?>

            <!--Intro Text--> 
                <p>You are currently already logged in as <b><?php echo $_SESSION['username']; ?></b></p>
            <!--End Intro Text-->

            <!--New Lines-->
                <br /><br />
            <!--End New Lines-->

            <p><a href="membership.php">Click here to go back to the membership system.</a></p>

            <!--New Lines-->
                <br /><br />
            <!--End New Lines-->

    <?php

        
    }
        else
        {
        
    //If action is login and the loggedin session equals "0" then show log in form.

            //if "mode" is equal to "new" then show a blank form to log in.
            
    if($_GET['mode'] == 'new')
            {
                include 
    "includes/login.inc.php";

            
    //if "mode" is equal to "complete" then process log in request
            
    }else if($_GET['mode'] == 'complete')
            {

                
    //if the form named "login" has been submitted then process log in request.
                
    if($_POST['login'])
                {
                    
    $username $_POST['username'];
                    
    $password md5($_POST['password']);
                    
    $info_query mysql_query("SELECT * FROM atm_users WHERE username='$username'") or die(mysql_error());
                    
    $info_row mysql_fetch_array($info_query);
                    
                    
    //If the inputted password does NOT equal the password stored in the database for that username then display incorrect username or password text.
                    
    if($info_row['password'] != $password)
                    {
                        echo 
    "Incorrect username or password!";
                        
                    
    //if the inputted password DOES equal the password in the database for that username then display success logged in message.
                    
    }else
                    {
                        
    $user_query mysql_query("SELECT * FROM atm_users WHERE username='$username'") or die(mysql_error());
                        
    $user_row mysql_fetch_array($user_query);
                    
                        
    $_SESSION['username']=$user_row['username'];
                        
    $_SESSION['userid']=$user_row['id'];
                        
    $_SESSION['loggedin']=1
                    
                        
    //setcookie("id", $user_row['id'],time()+(60*60*24*5), "/", "");
                        //setcookie("pass", $user_row['password'],time()+(60*60*24*5), "/", "");
                        
    echo "You're now successfully logged in to the Membership System. Please click <a href=\"membership.php\">here</a> to go to the Membership System main page";
                    
                    }
                }
            }
                    
        } 


    //NEXT SECTION

    //If the action equals "register" and loggedin session equals 1 then display a already registered and logged in message.
    if ($_GET['action'] == "register" )
    {

        if (
    $_SESSION['loggedin'] == 1
        {
            echo 
    "You are already registered and logged in as <b>".$_SESSION['username']."</b>";
            echo 
    '<!--New Lines-->
                <br /><br />
            <!--End New Lines-->
            <p><a href="membership.php">Click here to go back to the membership system.</a></p
            <!--New Lines-->
                <br /><br />
            <!--End New Lines-->'
    ;
        
    //if action equals "register" and loggedin session DOES NOT equal 1.
        
    }else
        {
        
            
    //If "mode" equals new then show new registration form.
            
    if($_GET['mode'] == 'new')
            {
                include 
    "includes/register.inc.php";
            
            
    //If "mode" equals "complete" then process new registration.
            
    }else
            {
                if(
    $_GET['mode'] == 'complete')
                {

                    
    //If "register" is not set then say that the registration form has not been completed.
                    
    if(!$_POST['register'])
                    {
                        echo 
    "You haven't gone through the registration process, try again.";
                    
                    
    //If "register" HAS been set then continue to process the form.
                    
    }else
                    {
                        
    // Some variables for what the user sends
                        
    $username $_POST['user'];
                        
    $password $_POST['password'];
                        
    $cpassword $_POST['cpassword'];
                        
    $email $_POST['email'];
                        
    $agree $_POST['agree'];
                        
    // If any fields are left out

                        //say a field was missed if any fields are empty.
                        
    if($username == NULL || $password == NULL || $cpassword NULL || $email == NULL || $agree == NULL)
                        {
                            echo 
    "You missed out a required field";
                        
    //If no fields are missed then continue.
                        
    }else
                        {
                            
    $password $_POST['password'];
                            
    $cpassword $_POST['cpassword'];
                            
    // If the passwords do not match
                            
    if($password != $cpassword)
                            {
                                echo 
    "Passwords do not match";
                            }else
                            {
                                
    // This encrypts the password
                                
    $password md5($password);
                                
    // Checking if username/email allready exists in the DB
                                
    $checkname mysql_query("SELECT username FROM atm_users WHERE username='$username'");
                                
    $checknamemysql_num_rows($checkname);
                                
    $checkemail mysql_query("SELECT email FROM atm_users WHERE email='$email'");
                                
    $checkemail mysql_num_rows($checkemail);
                                if (
    $checkemail || $checkname 0)
                                {
                                    echo 
    "The username or email is already in use";
                                }else
                                {
                                    
    $username htmlspecialchars($username);
                                    
    $password htmlspecialchars($password);
                                    
    $email htmlspecialchars($email);
                                    
    $add_user mysql_query("INSERT INTO atm_users SET id='NULL', username='$username', password='$password', email='$email'");
                                    echo 
    "Thankyou for registering. Please click <a href=\"membership.php\">here</a> to go to the Membership System homepage. You can then log in with your Username and Password.";

                                }
                            }
                        }
                    }
                }
            } 
        }
    }

    //NEXT SECTION

    //If action equals "logout"
    if ($_GET['action'] == "logout" )
    {
        
    //If the logged in session equals 1 then log user out.
        
    if ($_SESSION['loggedin'] == 1
        {
            unset(
    $_SESSION['username']);
            unset(
    $_SESSION['id']);
            unset(
    $_SESSION['loggedin']);
            
            echo 
    'Thanks for logging out. <a href="membership.php">Click here to go back to the membership system.</a>';
            
        }
    }


    ?>

    <?php
    //echo '<br /><br />';
    //Just to show the current value of the loggedin session variable.
    //echo 'Loggedin session variable currently is '.$_SESSION['loggedin'].'<br />';
    //echo 'Username session variable currently is '.$_SESSION['username'];

    ?>

    <!--New Lines-->
    <br /><br />
    <!--End New Lines-->

    <!--################################################# - END PAGE CONTENT - ####################################################-->
    <?php
    include ('template/templatebottom.php');
    ?>
    Please help figure out why I am getting these errors!

    Regards,
    Neil

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Hi Neil,

    2 ways to resolve it

    1/ check if the variable exists before trying to evaluate it:
    PHP Code:
    if((isset($_GET['action']) && ($_GET['action'] == 'whatever'))) { 
    or
    2/ silence the errors using the @ surpressor
    PHP Code:
    if (@$_GET['action'] == ""
    However it is always better to fix errors than circumvent them!

    (or just turn error reporting off!)
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,891
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks,
    I know this may seem stupid but could you please write the following code in it's english equivalent just so I 100&#37; know what it is trying to do.

    if((isset($_GET['action']) && ($_GET['action'] == 'whatever'))) {

  4. #4
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,891
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    I have changed it to this but it is still not working. Can you check it please?

    PHP Code:
    <?php
    $pagetitle 
    'Membership System';
    include (
    'template/templatetop.php');

    ################################################# - EXTRA PHP CODE - ####################################################

    ################################################# - END EXTRA PHP CODE - ####################################################



    ?>
    <!--################################################# - START PAGE CONTENT - ####################################################-->

    <?php 

    //error_reporting(0);

    //$_SESSION['loggedin'] = 0;
    //$_SESSION['username'] = 'tester';

    ?>

    <!--Code for every membership page-->

    <img src="img/small_graphics/memshipcard.png" alt="Alton Towers Mania membership System" /><br />

    <!--End code for every membership page-->



    <?php
    //If no action is set and a user is not logged in then show defult page state.
    if (!isset($_GET['action']))
    {
        
    $_GET['action'] == '';

    }else
    {

    if (
    $_GET['action'] == '')
    {

        if (
    $_SESSION['loggedin'] == 0){

    ?>

            <!--Intro Text--> 
            <p>Welcome to the Alton Towers Mania Membership System. Registering as part of the membership system will allow you to be more integrated with the site and give you access to do more exciting features, like submitting your high score on Duel to the high score board to tracking what rides you have ridden as well as which are your favourite rides at the park! The Duel Score board and favourites are coming very very soon! Please note that your Forum Community membership account is not the same as your membership account for this system.</p>
            <!--End Intro Text-->

            <!--New Lines-->
                <br /><br />
            <!--End New Lines-->

            <p class="center mediumheadings"><a href="membership.php?action=login&mode=new">Log In</a>&nbsp;&nbsp;&nbsp;: :&nbsp;&nbsp;&nbsp;<a href="membership.php?action=register&mode=new">Register</a></p>

    <?php
        

        else 
        {
        
    //If a user is logged in then show logged in page state
    ?>

            <!--Intro Text--> 
            <p>Welcome to the Alton Towers Mania Membership System. Now you have logged in you can visit the various links below to access different parts of the site which support the membership system. Any areas of this site where you see the membership system icon, allow you to use your account with them. You can log out of the membership system at anytime using the "Log Out" link to the left.</p>
            <!--End Intro Text-->

            <!--New Lines-->
                <br /><br />
            <!--End New Lines-->

            <ul>
                <li><a href="ridetracker.php">Ride Tracker</a></li>
                <li><!--<a href="favouriterides.php">-->Favourites</a></li>
                <li><!--<a href="duelboard.php">-->Duel Score Board</a></li>
            </ul>

    <?php

        
    }


    //NEXT SECTION
    //If the action is "login" and the loggedin session already equals 1 then display the already logged in message.
    if ($_GET['action'] == "login" )
    {
     
        if (
    $_SESSION['loggedin'] == 1
        {

    ?>

            <!--Intro Text--> 
                <p>You are currently already logged in as <b><?php echo $_SESSION['username']; ?></b></p>
            <!--End Intro Text-->

            <!--New Lines-->
                <br /><br />
            <!--End New Lines-->

            <p><a href="membership.php">Click here to go back to the membership system.</a></p>

            <!--New Lines-->
                <br /><br />
            <!--End New Lines-->

    <?php

        
    }
        else
        {
        
    //If action is login and the loggedin session equals "0" then show log in form.

            //if "mode" is equal to "new" then show a blank form to log in.
            
    if($_GET['mode'] == 'new')
            {
                include 
    "includes/login.inc.php";

            
    //if "mode" is equal to "complete" then process log in request
            
    }else if($_GET['mode'] == 'complete')
            {

                
    //if the form named "login" has been submitted then process log in request.
                
    if($_POST['login'])
                {
                    
    $username $_POST['username'];
                    
    $password md5($_POST['password']);
                    
    $info_query mysql_query("SELECT * FROM atm_users WHERE username='$username'") or die(mysql_error());
                    
    $info_row mysql_fetch_array($info_query);
                    
                    
    //If the inputted password does NOT equal the password stored in the database for that username then display incorrect username or password text.
                    
    if($info_row['password'] != $password)
                    {
                        echo 
    "Incorrect username or password!";
                        
                    
    //if the inputted password DOES equal the password in the database for that username then display success logged in message.
                    
    }else
                    {
                        
    $user_query mysql_query("SELECT * FROM atm_users WHERE username='$username'") or die(mysql_error());
                        
    $user_row mysql_fetch_array($user_query);
                    
                        
    $_SESSION['username']=$user_row['username'];
                        
    $_SESSION['userid']=$user_row['id'];
                        
    $_SESSION['loggedin']=1
                    
                        
    //setcookie("id", $user_row['id'],time()+(60*60*24*5), "/", "");
                        //setcookie("pass", $user_row['password'],time()+(60*60*24*5), "/", "");
                        
    echo "You're now successfully logged in to the Membership System. Please click <a href=\"membership.php\">here</a> to go to the Membership System main page";
                    
                    }
                }
            }
                    
        } 
    }
    }
     

    //NEXT SECTION

    //If the action equals "register" and loggedin session equals 1 then display a already registered and logged in message.
    if ($_GET['action'] == "register" )
    {

        if (
    $_SESSION['loggedin'] == 1
        {
            echo 
    "You are already registered and logged in as <b>".$_SESSION['username']."</b>";
            echo 
    '<!--New Lines-->
                <br /><br />
            <!--End New Lines-->
            <p><a href="membership.php">Click here to go back to the membership system.</a></p
            <!--New Lines-->
                <br /><br />
            <!--End New Lines-->'
    ;
        
    //if action equals "register" and loggedin session DOES NOT equal 1.
        
    }else
        {
        
            
    //If "mode" equals new then show new registration form.
            
    if($_GET['mode'] == 'new')
            {
                include 
    "includes/register.inc.php";
            
            
    //If "mode" equals "complete" then process new registration.
            
    }else
            {
                if(
    $_GET['mode'] == 'complete')
                {

                    
    //If "register" is not set then say that the registration form has not been completed.
                    
    if(!$_POST['register'])
                    {
                        echo 
    "You haven't gone through the registration process, try again.";
                    
                    
    //If "register" HAS been set then continue to process the form.
                    
    }else
                    {
                        
    // Some variables for what the user sends
                        
    $username $_POST['user'];
                        
    $password $_POST['password'];
                        
    $cpassword $_POST['cpassword'];
                        
    $email $_POST['email'];
                        
    $agree $_POST['agree'];
                        
    // If any fields are left out

                        //say a field was missed if any fields are empty.
                        
    if($username == NULL || $password == NULL || $cpassword NULL || $email == NULL || $agree == NULL)
                        {
                            echo 
    "You missed out a required field";
                        
    //If no fields are missed then continue.
                        
    }else
                        {
                            
    $password $_POST['password'];
                            
    $cpassword $_POST['cpassword'];
                            
    // If the passwords do not match
                            
    if($password != $cpassword)
                            {
                                echo 
    "Passwords do not match";
                            }else
                            {
                                
    // This encrypts the password
                                
    $password md5($password);
                                
    // Checking if username/email allready exists in the DB
                                
    $checkname mysql_query("SELECT username FROM atm_users WHERE username='$username'");
                                
    $checknamemysql_num_rows($checkname);
                                
    $checkemail mysql_query("SELECT email FROM atm_users WHERE email='$email'");
                                
    $checkemail mysql_num_rows($checkemail);
                                if (
    $checkemail || $checkname 0)
                                {
                                    echo 
    "The username or email is already in use";
                                }else
                                {
                                    
    $username htmlspecialchars($username);
                                    
    $password htmlspecialchars($password);
                                    
    $email htmlspecialchars($email);
                                    
    $add_user mysql_query("INSERT INTO atm_users SET id='NULL', username='$username', password='$password', email='$email'");
                                    echo 
    "Thankyou for registering. Please click <a href=\"membership.php\">here</a> to go to the Membership System homepage. You can then log in with your Username and Password.";

                                }
                            }
                        }
                    }
                }
            } 
        }
    }

    //NEXT SECTION

    //If action equals "logout"
    if ($_GET['action'] == "logout" )
    {
        
    //If the logged in session equals 1 then log user out.
        
    if ($_SESSION['loggedin'] == 1
        {
            unset(
    $_SESSION['username']);
            unset(
    $_SESSION['id']);
            unset(
    $_SESSION['loggedin']);
            
            echo 
    'Thanks for logging out. <a href="membership.php">Click here to go back to the membership system.</a>';
            
        }
    }


    ?>

    <?php
    //echo '<br /><br />';
    //Just to show the current value of the loggedin session variable.
    //echo 'Loggedin session variable currently is '.$_SESSION['loggedin'].'<br />';
    //echo 'Username session variable currently is '.$_SESSION['username'];

    ?>

    <!--New Lines-->
    <br /><br />
    <!--End New Lines-->

    <!--################################################# - END PAGE CONTENT - ####################################################-->
    <?php
    include ('template/templatebottom.php');
    ?>

  5. #5
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Hi Neil
    sorry I didnt get back to you on this, have you got it working yet?

    The code in plain English:
    if((isset($_GET['action']) && ($_GET['action'] == 'whatever'))) {

    if the $_GET['action'] variable has been sent AND it equals the value 'whatever'......
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  6. #6
    SitePoint Addict CVPer's Avatar
    Join Date
    Sep 2007
    Location
    Vancouver, BC, Canada
    Posts
    233
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rctneil View Post
    ... Can you check it please?...
    it may be better for people who are willing to help you if you can post the error message.
    * @location Vancouver, BC, Canada
    * @name Steve
    * @job PHP/MySQL, Drupal, WordPress Developer

  7. #7
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,891
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Ok, Here goes,

    Full page code:

    PHP Code:
    <?php
    $pagetitle 
    'Membership System';
    include (
    'template/templatetop.php');

    ################################################# - EXTRA PHP CODE - ####################################################

    ################################################# - END EXTRA PHP CODE - ####################################################



    ?>
    <!--################################################# - START PAGE CONTENT - ####################################################-->

    <?php 

    //error_reporting(0);

    //$_SESSION['loggedin'] = 0;
    //$_SESSION['username'] = 'tester';

    ?>

    <!--Code for every membership page-->

    <img src="img/small_graphics/memshipcard.png" alt="Alton Towers Mania membership System" /><br />

    <!--End code for every membership page-->



    <?php
    //If no action is set and a user is not logged in then show defult page state.
    if ((!isset($_GET['action'])) && (!isset($_SESSION['loggedin'] == 0)))
    {



    ?>

            <!--Intro Text--> 
            <p>Welcome to the Alton Towers Mania Membership System. Registering as part of the membership system will allow you to be more integrated with the site and give you access to do more exciting features, like submitting your high score on Duel to the high score board to tracking what rides you have ridden as well as which are your favourite rides at the park! The Duel Score board and favourites are coming very very soon! Please note that your Forum Community membership account is not the same as your membership account for this system.</p>
            <!--End Intro Text-->

            <!--New Lines-->
                <br /><br />
            <!--End New Lines-->

            <p class="center mediumheadings"><a href="membership.php?action=login&mode=new">Log In</a>&nbsp;&nbsp;&nbsp;: :&nbsp;&nbsp;&nbsp;<a href="membership.php?action=register&mode=new">Register</a></p>

    <?php
        

        else 
        {
        
    //If a user is logged in then show logged in page state
    ?>

            <!--Intro Text--> 
            <p>Welcome to the Alton Towers Mania Membership System. Now you have logged in you can visit the various links below to access different parts of the site which support the membership system. Any areas of this site where you see the membership system icon, allow you to use your account with them. You can log out of the membership system at anytime using the "Log Out" link to the left.</p>
            <!--End Intro Text-->

            <!--New Lines-->
                <br /><br />
            <!--End New Lines-->

            <ul>
                <li><a href="ridetracker.php">Ride Tracker</a></li>
                <li><!--<a href="favouriterides.php">-->Favourites</a></li>
                <li><!--<a href="duelboard.php">-->Duel Score Board</a></li>
            </ul>

    <?php

        
    }


    //NEXT SECTION
    //If the action is "login" and the loggedin session already equals 1 then display the already logged in message.
    if ($_GET['action'] == "login" )
    {
     
        if (
    $_SESSION['loggedin'] == 1
        {

    ?>

            <!--Intro Text--> 
                <p>You are currently already logged in as <b><?php echo $_SESSION['username']; ?></b></p>
            <!--End Intro Text-->

            <!--New Lines-->
                <br /><br />
            <!--End New Lines-->

            <p><a href="membership.php">Click here to go back to the membership system.</a></p>

            <!--New Lines-->
                <br /><br />
            <!--End New Lines-->

    <?php

        
    }
        else
        {
        
    //If action is login and the loggedin session equals "0" then show log in form.

            //if "mode" is equal to "new" then show a blank form to log in.
            
    if($_GET['mode'] == 'new')
            {
                include 
    "includes/login.inc.php";

            
    //if "mode" is equal to "complete" then process log in request
            
    }else if($_GET['mode'] == 'complete')
            {

                
    //if the form named "login" has been submitted then process log in request.
                
    if($_POST['login'])
                {
                    
    $username $_POST['username'];
                    
    $password md5($_POST['password']);
                    
    $info_query mysql_query("SELECT * FROM atm_users WHERE username='$username'") or die(mysql_error());
                    
    $info_row mysql_fetch_array($info_query);
                    
                    
    //If the inputted password does NOT equal the password stored in the database for that username then display incorrect username or password text.
                    
    if($info_row['password'] != $password)
                    {
                        echo 
    "Incorrect username or password!";
                        
                    
    //if the inputted password DOES equal the password in the database for that username then display success logged in message.
                    
    }else
                    {
                        
    $user_query mysql_query("SELECT * FROM atm_users WHERE username='$username'") or die(mysql_error());
                        
    $user_row mysql_fetch_array($user_query);
                    
                        
    $_SESSION['username']=$user_row['username'];
                        
    $_SESSION['userid']=$user_row['id'];
                        
    $_SESSION['loggedin']=1
                    
                        
    //setcookie("id", $user_row['id'],time()+(60*60*24*5), "/", "");
                        //setcookie("pass", $user_row['password'],time()+(60*60*24*5), "/", "");
                        
    echo "You're now successfully logged in to the Membership System. Please click <a href=\"membership.php\">here</a> to go to the Membership System main page";
                    
                    }
                }
            }
                    
        } 
    }

     

    //NEXT SECTION

    //If the action equals "register" and loggedin session equals 1 then display a already registered and logged in message.
    if ($_GET['action'] == "register" )
    {

        if (
    $_SESSION['loggedin'] == 1
        {
            echo 
    "You are already registered and logged in as <b>".$_SESSION['username']."</b>";
            echo 
    '<!--New Lines-->
                <br /><br />
            <!--End New Lines-->
            <p><a href="membership.php">Click here to go back to the membership system.</a></p
            <!--New Lines-->
                <br /><br />
            <!--End New Lines-->'
    ;
        
    //if action equals "register" and loggedin session DOES NOT equal 1.
        
    }else
        {
        
            
    //If "mode" equals new then show new registration form.
            
    if($_GET['mode'] == 'new')
            {
                include 
    "includes/register.inc.php";
            
            
    //If "mode" equals "complete" then process new registration.
            
    }else
            {
                if(
    $_GET['mode'] == 'complete')
                {

                    
    //If "register" is not set then say that the registration form has not been completed.
                    
    if(!$_POST['register'])
                    {
                        echo 
    "You haven't gone through the registration process, try again.";
                    
                    
    //If "register" HAS been set then continue to process the form.
                    
    }else
                    {
                        
    // Some variables for what the user sends
                        
    $username $_POST['user'];
                        
    $password $_POST['password'];
                        
    $cpassword $_POST['cpassword'];
                        
    $email $_POST['email'];
                        
    $agree $_POST['agree'];
                        
    // If any fields are left out

                        //say a field was missed if any fields are empty.
                        
    if($username == NULL || $password == NULL || $cpassword NULL || $email == NULL || $agree == NULL)
                        {
                            echo 
    "You missed out a required field";
                        
    //If no fields are missed then continue.
                        
    }else
                        {
                            
    $password $_POST['password'];
                            
    $cpassword $_POST['cpassword'];
                            
    // If the passwords do not match
                            
    if($password != $cpassword)
                            {
                                echo 
    "Passwords do not match";
                            }else
                            {
                                
    // This encrypts the password
                                
    $password md5($password);
                                
    // Checking if username/email allready exists in the DB
                                
    $checkname mysql_query("SELECT username FROM atm_users WHERE username='$username'");
                                
    $checknamemysql_num_rows($checkname);
                                
    $checkemail mysql_query("SELECT email FROM atm_users WHERE email='$email'");
                                
    $checkemail mysql_num_rows($checkemail);
                                if (
    $checkemail || $checkname 0)
                                {
                                    echo 
    "The username or email is already in use";
                                }else
                                {
                                    
    $username htmlspecialchars($username);
                                    
    $password htmlspecialchars($password);
                                    
    $email htmlspecialchars($email);
                                    
    $add_user mysql_query("INSERT INTO atm_users SET id='NULL', username='$username', password='$password', email='$email'");
                                    echo 
    "Thankyou for registering. Please click <a href=\"membership.php\">here</a> to go to the Membership System homepage. You can then log in with your Username and Password.";

                                }
                            }
                        }
                    }
                }
            } 
        }
    }

    //NEXT SECTION

    //If action equals "logout"
    if ($_GET['action'] == "logout" )
    {
        
    //If the logged in session equals 1 then log user out.
        
    if ($_SESSION['loggedin'] == 1
        {
            unset(
    $_SESSION['username']);
            unset(
    $_SESSION['id']);
            unset(
    $_SESSION['loggedin']);
            
            echo 
    'Thanks for logging out. <a href="membership.php">Click here to go back to the membership system.</a>';
            
        }
    }


    ?>

    <?php
    //echo '<br /><br />';
    //Just to show the current value of the loggedin session variable.
    //echo 'Loggedin session variable currently is '.$_SESSION['loggedin'].'<br />';
    //echo 'Username session variable currently is '.$_SESSION['username'];

    ?>

    <!--New Lines-->
    <br /><br />
    <!--End New Lines-->

    <!--################################################# - END PAGE CONTENT - ####################################################-->
    <?php
    include ('template/templatebottom.php');
    ?>
    And the current error i am getting:


    Parse error: syntax error, unexpected T_IS_EQUAL, expecting ',' or ')' in D:\wamp\www\template atm\membership.php on line 33



    Can anybosy try and fix the page and sort the code out?

  8. #8
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Evening Neil,
    try the following:
    PHP Code:
    <?php
    $pagetitle 
    'Membership System';
    include (
    'template/templatetop.php');

    ################################################# - EXTRA PHP CODE - ####################################################
    /*
    Register the incoming variables as simple variable
    */
    $action = isset($_GET['action']) ? $_GET['action'] : 0;
    $logged_in = isset($_SESSION['loggedin']) ? 0


    ################################################# - END EXTRA PHP CODE - ####################################################



    ?>
    <!--################################################# - START PAGE CONTENT - ####################################################-->

    <?php 

    //error_reporting(0);

    //$_SESSION['loggedin'] = 0;
    //$_SESSION['username'] = 'tester';

    ?>

    <!--Code for every membership page-->

    <img src="img/small_graphics/memshipcard.png" alt="Alton Towers Mania membership System" /><br />

    <!--End code for every membership page-->



    <?php
    //If no action is set and a user is not logged in then show defult page state.
    if (($action != 0) && ($logged_in == 0))
    {



    ?>

            <!--Intro Text--> 
            <p>Welcome to the Alton Towers Mania Membership System. Registering as part of the membership system will allow you to be more integrated with the site and give you access to do more exciting features, like submitting your high score on Duel to the high score board to tracking what rides you have ridden as well as which are your favourite rides at the park! The Duel Score board and favourites are coming very very soon! Please note that your Forum Community membership account is not the same as your membership account for this system.</p>
            <!--End Intro Text-->

            <!--New Lines-->
                <br /><br />
            <!--End New Lines-->

            <p class="center mediumheadings"><a href="membership.php?action=login&mode=new">Log In</a>&nbsp;&nbsp;&nbsp;: :&nbsp;&nbsp;&nbsp;<a href="membership.php?action=register&mode=new">Register</a></p>

    <?php
        

        else 
        {
        
    //If a user is logged in then show logged in page state
    ?>

            <!--Intro Text--> 
            <p>Welcome to the Alton Towers Mania Membership System. Now you have logged in you can visit the various links below to access different parts of the site which support the membership system. Any areas of this site where you see the membership system icon, allow you to use your account with them. You can log out of the membership system at anytime using the "Log Out" link to the left.</p>
            <!--End Intro Text-->

            <!--New Lines-->
                <br /><br />
            <!--End New Lines-->

            <ul>
                <li><a href="ridetracker.php">Ride Tracker</a></li>
                <li><!--<a href="favouriterides.php">-->Favourites</a></li>
                <li><!--<a href="duelboard.php">-->Duel Score Board</a></li>
            </ul>

    <?php

        
    }


    //NEXT SECTION
    //If the action is "login" and the loggedin session already equals 1 then display the already logged in message.
    if (($action == "login" ) && ($logged_in == 1))
    {
     

    ?>

            <!--Intro Text--> 
                <p>You are currently already logged in as <b><?php echo $_SESSION['username']; ?></b></p>
            <!--End Intro Text-->

            <!--New Lines-->
                <br /><br />
            <!--End New Lines-->

            <p><a href="membership.php">Click here to go back to the membership system.</a></p>

            <!--New Lines-->
                <br /><br />
            <!--End New Lines-->

    <?php

        
    }
        else
        {
        
    //If action is login and the loggedin session equals "0" then show log in form.

            //if "mode" is equal to "new" then show a blank form to log in.
            
    if($_GET['mode'] == 'new')
            {
                include 
    "includes/login.inc.php";

            
    //if "mode" is equal to "complete" then process log in request
            
    }else if($_GET['mode'] == 'complete')
            {

                
    //if the form named "login" has been submitted then process log in request.
                
    if($_POST['login'])
                {
                    
    $username $_POST['username'];
                    
    $password md5($_POST['password']);
                    
    $info_query mysql_query("SELECT * FROM atm_users WHERE username='$username'") or die(mysql_error());
                    
    $info_row mysql_fetch_array($info_query);
                    
                    
    //If the inputted password does NOT equal the password stored in the database for that username then display incorrect username or password text.
                    
    if($info_row['password'] != $password)
                    {
                        echo 
    "Incorrect username or password!";
                        
                    
    //if the inputted password DOES equal the password in the database for that username then display success logged in message.
                    
    }else
                    {
                        
    $user_query mysql_query("SELECT * FROM atm_users WHERE username='$username'") or die(mysql_error());
                        
    $user_row mysql_fetch_array($user_query);
                    
                        
    $_SESSION['username']=$user_row['username'];
                        
    $_SESSION['userid']=$user_row['id'];
                        
    $_SESSION['loggedin']=1
                    
                        
    //setcookie("id", $user_row['id'],time()+(60*60*24*5), "/", "");
                        //setcookie("pass", $user_row['password'],time()+(60*60*24*5), "/", "");
                        
    echo "You're now successfully logged in to the Membership System. Please click <a href=\"membership.php\">here</a> to go to the Membership System main page";
                    
                    }
                }
            }
                    
        } 
    }

     

    //NEXT SECTION

    //If the action equals "register" and loggedin session equals 1 then display a already registered and logged in message.
    if ($action == "register" )
    {

        if (
    $logged_in == 1
        {
            echo 
    "You are already registered and logged in as <b>".$_SESSION['username']."</b>";
            echo 
    '<!--New Lines-->
                <br /><br />
            <!--End New Lines-->
            <p><a href="membership.php">Click here to go back to the membership system.</a></p
            <!--New Lines-->
                <br /><br />
            <!--End New Lines-->'
    ;
        
    //if action equals "register" and loggedin session DOES NOT equal 1.
        
    }else
        {
        
            
    //If "mode" equals new then show new registration form.
            
    if($_GET['mode'] == 'new')
            {
                include 
    "includes/register.inc.php";
            
            
    //If "mode" equals "complete" then process new registration.
            
    }else
            {
                if(
    $_GET['mode'] == 'complete')
                {

                    
    //If "register" is not set then say that the registration form has not been completed.
                    
    if(!$_POST['register'])
                    {
                        echo 
    "You haven't gone through the registration process, try again.";
                    
                    
    //If "register" HAS been set then continue to process the form.
                    
    }else
                    {
                        
    // Some variables for what the user sends
                        
    $username $_POST['user'];
                        
    $password $_POST['password'];
                        
    $cpassword $_POST['cpassword'];
                        
    $email $_POST['email'];
                        
    $agree $_POST['agree'];
                        
    // If any fields are left out

                        //say a field was missed if any fields are empty.
                        
    if($username == NULL || $password == NULL || $cpassword NULL || $email == NULL || $agree == NULL)
                        {
                            echo 
    "You missed out a required field";
                        
    //If no fields are missed then continue.
                        
    }else
                        {
                            
    $password $_POST['password'];
                            
    $cpassword $_POST['cpassword'];
                            
    // If the passwords do not match
                            
    if($password != $cpassword)
                            {
                                echo 
    "Passwords do not match";
                            }else
                            {
                                
    // This encrypts the password
                                
    $password md5($password);
                                
    // Checking if username/email allready exists in the DB
                                
    $checkname mysql_query("SELECT username FROM atm_users WHERE username='$username'");
                                
    $checknamemysql_num_rows($checkname);
                                
    $checkemail mysql_query("SELECT email FROM atm_users WHERE email='$email'");
                                
    $checkemail mysql_num_rows($checkemail);
                                if (
    $checkemail || $checkname 0)
                                {
                                    echo 
    "The username or email is already in use";
                                }else
                                {
                                    
    $username htmlspecialchars($username);
                                    
    $password htmlspecialchars($password);
                                    
    $email htmlspecialchars($email);
                                    
    $add_user mysql_query("INSERT INTO atm_users SET id='NULL', username='$username', password='$password', email='$email'");
                                    echo 
    "Thankyou for registering. Please click <a href=\"membership.php\">here</a> to go to the Membership System homepage. You can then log in with your Username and Password.";

                                }
                            }
                        }
                    }
                }
            } 
        }
    }

    //NEXT SECTION

    //If action equals "logout"
    if ($action == "logout" )
    {
        
    //If the logged in session equals 1 then log user out.
        
    if ($_SESSION['loggedin'] == 1
        {
            unset(
    $_SESSION['username']);
            unset(
    $_SESSION['id']);
            unset(
    $_SESSION['loggedin']);
            
            echo 
    'Thanks for logging out. <a href="membership.php">Click here to go back to the membership system.</a>';
            
        }
    }


    ?>

    <?php
    //echo '<br /><br />';
    //Just to show the current value of the loggedin session variable.
    //echo 'Loggedin session variable currently is '.$_SESSION['loggedin'].'<br />';
    //echo 'Username session variable currently is '.$_SESSION['username'];

    ?>

    <!--New Lines-->
    <br /><br />
    <!--End New Lines-->

    <!--################################################# - END PAGE CONTENT - ####################################################-->
    <?php
    include ('template/templatebottom.php');
    ?>
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  9. #9
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,891
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any chance of posting that without the php tags as it goes all funny when I copy and paste it. It leaves new lines.

  10. #10
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Do you mean it adds lines between each code line? if so I have noticed that before and thought it was just my browser!

    if you quote the original message and copy the code from there it should be fine.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  11. #11
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,891
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, With the code you posted, I am getting this:

    Parse error: syntax error, unexpected '}' in D:\wamp\www\template atm\membership.php on line 152


    If i remove the } on line 152, I get the following errors:

    Notice: Undefined index: mode in D:\wamp\www\template atm\membership.php on line 112

    Notice: Undefined index: mode in D:\wamp\www\template atm\membership.php on line 117

    Notice: Undefined index: mode in D:\wamp\www\template atm\membership.php on line 177

    Notice: Undefined index: mode in D:\wamp\www\template atm\membership.php on line 184

    Notice: Undefined index: loggedin in D:\wamp\www\template atm\membership.php on line 251

  12. #12
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Sorry Neil, forgot to remove the closing } after taking out part of the if () else.

    for the mode index error, simply do the same as I did with the action

    PHP Code:
    $action = isset($_GET['action']) ? $_GET['action'] : 0;
    $logged_in = isset($_SESSION['loggedin']) ? 0
    $mode = isset($_GET['mode']) ? $_GET['mode'] : 0
    and replace every occurrence of $_GET['mode'] in the script with $mode.

    also replace $_SESSION['loggedin'] with $logged_in
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  13. #13
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,891
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When doing that, it gets rid of all errors but it shows the default page display as well as the log in form and the new registration form all underneath each other on the page!

  14. #14
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,099
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I have an app and noticed undefined index, I do fix all of my undefined variables but I noticed in my logs "undefined index" and assumed it was an array matter since all variables have been defined, the script does not use post or get so was confused to see this error. If you could explain what causes the undefined index error it would be a great help.

    Thanks
    Loren


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •