Results 1 to 8 of 8

Thread: $_POST['username'] NOT defined?!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    236

    Exclamation $_POST['username'] NOT defined?!

    What's wrong? It can't define what stands in this title, and the textbox's name sent HAS the name username

    PHP Code:
    <?php
        
    include('config.php');
        
    // connect to the mysql database server.
        
    mysql_connect ($dbhost$dbusername$dbuserpass);
        
    mysql_select_db($dbname) or die('Cannot select database');
        if ( isset( 
    $_COOKIE['SundhedU'] ) && isset( $_COOKIE['SundhedP'] ) )
        {
            
    header"Location: main.php" );
        }
        else
        {
        if(
    $_POST['username'] {
                
    //did they supply a password and username
                
    $username=$_POST['username'];
                
    $password=$_POST['password'];
                if (
    $password==NULL) { 
    echo 
    "<META HTTP-EQUIV='REFRESH' CONTENT='0;URL=index.php'>
    "
    ;
    }
                else
                {
                    
    $query mysql_query("SELECT username,password FROM users WHERE username = '$username'") or die(mysql_error());
                    
    $data mysql_fetch_array($query);
                    if(
    $data['password'] != md5($password))
                    { 
    echo 
    "<META HTTP-EQUIV='REFRESH' CONTENT='0;URL=index.php'>";
    }
                    else
                    {
                        if (isset(
    $_POST['husklogin']))
                        {
                            
    setcookie('SundhedU'$usernametime() + 3600 24 365);
                            
    setcookie('SundhedP'md5($password), time() + 3600 24 365);       
          
                            
    $query mysql_query("SELECT username,password FROM users WHERE username = '$username'") or die(mysql_error());
                            
    $row mysql_fetch_array($query);
                            
    $_SESSION["s_username"] = $row['username'];
                            
    header("Location: index.php");
                        }else{
                            
    $query mysql_query("SELECT username,password FROM users WHERE username = '$username'") or die(mysql_error());
                            
    $row mysql_fetch_array($query);
                            
    $_SESSION["s_username"] = $row['username'];
                            
    header("Location: index.php");
    }
                    }
                }
            }   
            }
    ?>

  2. #2
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: $_POST['username'] NOT defined?!

    shouldn't
    PHP Code:
     if($_POST['username'] { 
    be
    PHP Code:
     if(isset($_POST['username'])) { 

  3. #3
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: $_POST['username'] NOT defined?!

    As to do with the error message it means that you are trying to read a variable that has not been set. This is only a warning and does not affect your script, it will carry on as normal, you can change whether they are displayed or not via the php.ini file or by using error_reporting. But checking to seee if the variable has been set using isset() is much better.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    236

    Re: $_POST['username'] NOT defined?!

    Ok great! But the string
    PHP Code:
    $username=$_POST['username']; 
    returns NULL

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: $_POST['username'] NOT defined?!

    Can you post your form code?

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    236

    Re: $_POST['username'] NOT defined?!

    PHP Code:
    <form method='post' action='check.php'>
                  <
    left>Brugernavn 
                  
    <input type='text' name='username'>
                  <
    br>
                  
    Kodeord 
                  
    <input type='password' name='password'>           
                  <
    input name='husklogin' type='checkbox' value='husklogin' checked>
                  
    Husk mig&nbsp;&nbsp;
                  <
    input name='submit' type='submit' value='Login'>
                    <
    br>
                  <
    br><center>
                  <
    a href='opretbruger.php'>.: Opret bruger her :.</a><br>
                  <
    a href='glemt.php'>.: Glemt login? :.</a></center></form

  7. #7
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

    Re: $_POST['username'] NOT defined?!

    You could try using print_r($_POST);

    to see what is getting passed through

    or you could try

    echo $HTTP_POST_VARS['username'];

    or $_REQUEST['username];

    just a thought

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    236

    Re: $_POST['username'] NOT defined?!

    Still kinda dead :/

Posting Permissions

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



Click Here to Expand Forum to Full Width