Web Analytics Made Easy -
StatCounter strange error - CodingForum

Announcement

Collapse
No announcement yet.

strange error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • strange error

    Hi I have a little prob with a scrip..it gives this error in this lines:

    $username = $_POST['username'];
    $password = $_POST['password'];

    I don't know why, but it gives this error

    Notice: Undefined index: username in c:\program
    files\easyphp1-7\www\golo\login.php on line 7

    Notice: Undefined index: password in c:\program
    files\easyphp1-7\www\golo\login.php on line 8

    what am I doing wrong? Thanks

  • #2
    i am assuming this script is handling a form. and properly.
    might try
    PHP Code:
    $username $HTTP_POST_VARS['username']; 
    also, make sure the names in the script match those in the form.
    "There is more than one way to do it."

    Comment


    • #3
      further, make sure your form tag includes:
      Code:
      action="POST"
      and like dswimboy mentioned, make sure the html <input> tags include the "name" attribute.


      also, you may try putting in a

      PHP Code:
      phpinfo(); 
      and tell us what version of PHP you're running.

      -Celt

      Comment


      • #4
        the version of my php is:
        PHP Version 4.3.3

        and my html forms don't include atribut..

        here his the code of the form:

        Code:
        <form action="checkuser.php" method="post" name="" id="">
          <table width="50%" border="0" align="center" cellpadding="4" cellspacing="0">
            <tr>
              <td width="22%">Username</td>
              <td width="78%"><input name="username" type="text" id="username"></td>
            </tr>
            <tr>
              <td>Password</td>
              <td><input name="password" type="password" id="password"></td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td><p>
                <input type="submit" name="Submit" value="Submit">
              </p>
                <p>
                  </td>
            </tr>
          </table>
        
        </form>
        thanks
        Last edited by devil_online; Feb 29, 2004, 10:21 PM.

        Comment


        • #5
          try the following:
          PHP Code:
          $username $_POST["username"]; 
          if still no luck, try doing a
          PHP Code:
          foreach ($_POST as $key => $value) {
             print 
          $key " = " $value "<br/>\n";

          and tell us the results.

          Comment


          • #6
            well I put this

            <? error_reporting(0); ?>

            and worked..tanks

            Comment


            • #7
              Originally posted by devil_online
              well I put this

              <? error_reporting(0); ?>

              and worked..tanks
              Turning off error reporting doesn't fix the problem. Ignoring the problem can cause you problems elsewhere.
              Spookster
              CodingForum Supreme Overlord
              All Hail Spookster

              Comment


              • #8
                Originally posted by dswimboy
                i am assuming this script is handling a form. and properly.
                might try
                PHP Code:
                $username $HTTP_POST_VARS['username']; 
                That is deprecated. Unless they are using an old version of PHP prior to 4.1.0 I believe then you should not use that.
                Spookster
                CodingForum Supreme Overlord
                All Hail Spookster

                Comment


                • #9
                  You get the notices because you are running php in 'anale mode'. Set the errorreporting to

                  error_reporting(E_ALL ^ E_NOTICE);

                  --> so this reports all errors except notices.

                  You get the notive because you didn't define the variables. If you have register_globals=on , then this creates a possible securityrisk. (It is exactly this non-defining of the variables that creates the risk, and not the register_globals)

                  So it's mainly a notice that your using bad coding-style.
                  Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

                  Comment


                  • #10
                    So grabbing variables using $_POST[] is bad?

                    I thought you should use $_POST to get variables, and having your globals on and referring to the variable directly is bad (security risks...).

                    For example:
                    PHP Code:
                    $_POST["username"
                    instead of:
                    PHP Code:
                    $username 
                    I'm sure this may have been a topic in the past somewhere, but I'm a little bit new here.

                    Thanks,
                    Sadiq.

                    Comment


                    • #11
                      Originally posted by sad69
                      So grabbing variables using $_POST[] is bad?

                      I thought you should use $_POST to get variables, and having your globals on and referring to the variable directly is bad (security risks...).

                      For example:
                      PHP Code:
                      $_POST["username"
                      instead of:
                      PHP Code:
                      $username 
                      I'm sure this may have been a topic in the past somewhere, but I'm a little bit new here.

                      Thanks,
                      Sadiq.
                      I think you don't quite understand. What raf said has nothing to do with whether or not you should use the superglobal $_POST array. You should not have register_globals set to on. With register globals on you would be able to directly access the data in the superglobal $_POST array simply by using a variable that has the same name as the form field. To access that data you should always just use the superglobal and not rely on register_globals being enabled.
                      Spookster
                      CodingForum Supreme Overlord
                      All Hail Spookster

                      Comment


                      • #12
                        nor are we doing what is "supposed" to be done. what is supposed to work, doesn't work for devil_online, so we're trying other alternatives to find out where he went wrong.
                        "There is more than one way to do it."

                        Comment


                        • #13
                          the only thing so far I make it work is :
                          error_reporting(E_ALL ^ E_NOTICE);

                          Two questions
                          where I define the variables? it's in html form? and how do I do it?.

                          How can I turn globals on?

                          thanks

                          Comment


                          • #14
                            you dont want to turn register_globals on & its not related to your problem.

                            nor in this case is variable declaration , you cant declare the $_POST variables without overwriting user submitted $_POST varables so in essence <input type="text" name="username" /> is the variable declaration as far as the receiving script is concerned.

                            You will only get that error before the variables have been posted ... e.g. if you display that code before anyone has pressed submit then the warning will occur , when the variables are set (by pressing submit and filling the $_POST array) then the warning should go away.

                            if the warnings are annoying you enough ... use

                            PHP Code:
                            <?
                            if( isset($_POST['username'] ,$_POST['password'] ) ){
                              
                            $username $_POST['username'] ;
                              
                            $password$_POST['password'] ;
                            }
                            ?>
                            and you can not lose ... in saying that you should not be trying this assignment in the first place until the form has been submitted , e.g normally such code is contained in a ..

                            PHP Code:
                            <?
                            if( isset($_POST['submit'] ){ //assuming a submit button called submit
                             /*do form processing here*/
                            }else{
                             
                            /*display form or whatever*/
                            }
                            ?>
                            block.

                            .....................................................................

                            There is the off chance that for some reason your _POST variable array is not being set , I hear this happens in IE6 under some circumstances, to test that try $_REQUEST['username'] etc which may solve the issue.
                            Last edited by firepages; Mar 2, 2004, 02:05 AM.
                            resistance is...

                            MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

                            Comment

                            Working...
                            X