Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form not passing variables to PHP via. post

    OK

    strange problem here. I am going to post 4 pages that I am using in a webpage under development and hopefully people can work their way around them.

    But basically loginform.php is not passing anything to logincheck.php even though the form is set method="post". You may notice on the last page some output where i have commented out the header re-direct. This is so that i can see what the variables are. They are coming out as blank. I have tried force using _REQUEST instead of _POST on this last page and this still does not find any results.

    I have tried googling the problem and some results seem to imply it could be a problem with my apache setup, is this likely?

    Sorry for how much code this is but i thought it best to give you everything.

    PHP Code:
    <?php

        session_start
    ();

        include_once 
    'included/doctype.php';

        echo 
    '<html>';

        include_once 
    'included/head.php';

        echo 
    '<body>';
        
        include_once 
    'included/div/banner.php';
        
        include_once 
    'included/div/menu.php';
        
        include_once 
    'included/div/login.php'// ***This is the important bit***
        
        
    include_once 'included/div/logged_in_menu.php';
        
        include_once 
    'included/div/logo.php';

        if (
    $_GET['page'] == null// If the page attribute is not set.
        
    {
            
    $page index;
        }
        else if (
    file_exists("included/main/" .$_GET['page'] . ".php")) // Only allow the attribute to be set if the file exists.
        
    {
            
    $page $_GET['page'];
        }
        else 
    // If the file does not exist or the page attribute is not set then default to index.php
        
    {
            
    $page index;
        }
        
        include_once 
    "included/main/$page.php";

        echo 
    '</body>';

        echo 
    '</html>';
    ?>
    PHP Code:
    <div id="login">

    <?php
        
    if(!isset($_SESSION['username']))
        {
            include 
    'included/loginform.php'// ***IMPORTANT***
        
    }
        else
        {
            
    $username $_SESSION['username'];
            
    $account_type $_SESSION['account_type'];
            echo 
    "$username is logged in with $account_type privileges.";

        echo 
    '<br />';
        echo 
    '<input type="button" value="Log Out" onclick="Javascript: document.location=\'included/logout.php\'" />';

        }
    ?>
    </div>
    PHP Code:
    <h3>LOG IN</h3>
    <form name="login" method="post" action="included/logincheck.php"> <!-- This does say post -->
        <p>Name:<br />
        <input id="username" type="text" maxlength="10" />
        <br />
        Password:<br />
        <input id="password" type="password" maxlength="255" />
        <br />
        <br />
        <input type="submit" id="submit" value="login" />
        </p>
        </form>

    <?
        $check 
    $_GET['login'];
        
        if (
    $check == invalid)
        {
            echo 
    "Incorrect Username or Password!";
            echo 
    '<br />';
            echo 
    $_GET['username'] . $_GET['password'];
        }
        else
        {
        }
    ?>
    PHP Code:
    <?php
        session_start
    ();
        
        include_once 
    'db_connection_open.php';
        
        
    $username $_POST['username'];
        
    $password $_POST['password'];
        
        
    $sql "SELECT * 
                FROM USERS
                WHERE USERNAME = '$username' 
                AND PASSWORD = '$password'"
    ;
         
        
    $result mysql_query($sql$connection)
            or die (
    "Couldn't perform query $sql <br />" mysql_error());
            
        
    $row mysql_fetch_array($result);
        
        if (
    $row != null)
        {
            
    $_SESSION['username'] = $row['USERNAME'];
            
    $_SESSION['account_type'] = $row['ACCOUNT_TYPE'];
            
    header("Location: ../index.php");
            exit();
        }
        else
        {
            echo 
    "Username: ".$username;
            echo 
    "<br />Pass: ".$password;
            
    //header("Location: ../index.php?login=invalid&username='$username'&password='$password'");
            //exit();
        
    }
        
        include_once 
    'db_connection_close.php';
    ?>

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    You have to name the input fields
    Code:
    <input type="text" name="username" ..

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Also, you should add quotes around invalid here.

    if ($check == 'invalid')

  • #4
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    cheers guys...

    i thought id="" was the same as name=""


  •  

    Posting Permissions

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