Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    On planet earth
    Posts
    101
    Rep Power
    11

    Error messages: PHP


    Recently I got back to designing a website but now encountering a problem that didn't exist when I had given up for the time being

    The error message I get is
    Undefined index: submit in F:\xampp\htdocs\Course1\index.php
    The code that it points to is
    Code:
    if( "Login" == $_POST['submit'] )
    I kept updating xampp and Netbeans continually between the time I gave up in which I had to delete htdocs and the mysql folders in the xampp folder in order for the application to un/install properly (of course I did back them up, but wouldn't recognise either if I had simply copied and pasted it back it)

    I use mainly mysqli because that is what I was taught to use on my php course

    Is this a xampp or localhost bug?
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    well, I find the error message pretty straightforward. It says that there is no POST parameter named "submit". So you probably viewed the page for the first time when there has not been a previous form submission.

    If you hadn't gotten this message previously it's because your PHP configuration supressed error message. So the problem always existed, but you just didn't see it before.

    You can fix the problem with
    PHP Code:
    if( isset( $_POST['submit'] ) && "Login" == $_POST['submit'] ) 
    But you might as well ignore the warning. Many developers tend to do that so that they can keep their code simple and don't have to add isset() everywhere.

    Comments on this post

    • cssbonding agrees : wow, diddly wow, thank you
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    On planet earth
    Posts
    101
    Rep Power
    11
    wow, thank you that worked, forgot to say that I am receiving

    Undefined variable: message in F:\xampp\htdocs\index.php on line 52
    PHP Code:
    <?php if($message){echo("<p class='error_msg'>{$message}</p>");}?>
    I hazard to guess that this is another suppressed error message that I am getting?

    The variable $message has been defined earlier on
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Originally Posted by cssbonding
    I hazard to guess that this is another suppressed error message that I am getting?
    That's true. It's basically the same "error" as above: Instead of specifically checking for isset(), you just test if the variable is truthy. This isn't necessarily wrong, but it will trigger those warnings.



    Originally Posted by cssbonding
    The variable $message has been defined earlier on
    Maybe in another context (e. g. an "if" statement that isn't executed), but it's not defined at this point of time.
    Last edited by Jacques1; November 21st, 2012 at 06:40 AM.
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    On planet earth
    Posts
    101
    Rep Power
    11
    You mean it will work without the correction live? (my site isn't currently live in the internet)
  10. #6
  11. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    This is a configuration issue, so it depends on the PHP configuration on your webserver. If the server is configured to not display any error message (like it should be), yes, your script will "work" in the sense that you won't see the warnings. If the configuration does display error messages, you'll either have to change it or overwrite it at runtime with error_reporting(0).
    Last edited by Jacques1; November 21st, 2012 at 08:24 AM.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    697
    Rep Power
    7
    N just to toss my opinion in, if you feel Jacques1 is telling you to adjust your server's error reporting, I hope this is not true. Only production servers should have errors suppressed. Development servers, as it sounds you are currently on with the files, should be pumping out all tons of errors. This way the writer knows there's an issue and can correct the code, and not be mislead that everything is okay.

    EDIT: And ya, if you changed if($message) into if(isset($message)), you shouldn't get that error.


    EDIT2: Sorry. I overlooked the 'live' detail in your question. All should look good live as Jacques1 states.

    Comments on this post

    • cssbonding agrees : thanks
    • Jacques1 disagrees : He specifically asked if the errors will show up on his *live* system. If the live system displays any error messages, the configuration is wrong and must be changed or overwritten.
  14. #8
  15. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    On planet earth
    Posts
    101
    Rep Power
    11
    Originally Posted by Triple_Nothing
    N just to toss my opinion in, if you feel Jacques1 is telling you to adjust your server's error reporting, I hope this is not true. Only production servers should have errors suppressed. Development servers, as it sounds you are currently on with the files, should be pumping out all tons of errors. This way the writer knows there's an issue and can correct the code, and not be mislead that everything is okay.

    EDIT: And ya, if you changed if($message) into if(isset($message)), you shouldn't get that error.
    I am currently on localhost because I don't want to put my files on the web unless there is a hoster where I can put up test files for at least six months where I can at least get back in the frame of mind of web development
  16. #9
  17. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    On planet earth
    Posts
    101
    Rep Power
    11
    So I guess if there are any "if" statement, I have to insert "isset(variable or state)"?
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    697
    Rep Power
    7
    Well, only if it's written in the if($var) manner. Between the ()'s you are supposed to be pretty much writtin something that can be true/false. Your intent is to check if variable isset(). The reason for the error is because if the error is not set, it doesn't exist, so the if() cannot check if the statement is true or false.
  20. #11
  21. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Originally Posted by cssbonding
    So I guess if there are any "if" statement, I have to insert "isset(variable or state)"?
    No.

    As I already said, it's common practice to leave out the isset(). This is a valid way of coding. However, it will display those warnings while you work on your local test server (which is supposed to display all errors). You simply have to ignore them. When you put your scripts online, the warnings will not appear (if your live server is configured correctly and doesn't display any error messages).

    If you cannot possibly live with warnings during development, yes, then you have to use isset().
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    697
    Rep Power
    7
    As Jacques1 states, the isset() is not truely required. I'm not really sure on over-all if peeps prefer it or not. I, tho, am one to try n write my scripts error-free to avoid poor possibilities down the road. If you are looking for a temp host or such, I can offer you space. As long as it's nothing huge and all, like forums with thousands of visitors, it will be all good.
  24. #13
  25. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2002
    Location
    Seattle, U.S.A.
    Posts
    712
    Rep Power
    13
    As I already said, it's common practice to leave out the isset().
    I would propose that if the PHP gods deems this a warning, that you should consider not testing to see if the variable exists as bad coding practice. IMO I think that you should strive to have zero warnings in your site. Just my 2 cents.
  26. #14
  27. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    On planet earth
    Posts
    101
    Rep Power
    11
    Originally Posted by msteudel
    I would propose that if the PHP gods deems this a warning, that you should consider not testing to see if the variable exists as bad coding practice. IMO I think that you should strive to have zero warnings in your site. Just my 2 cents.
    I know that because somehow something isn't quite working on my localhost like it used too, search functions are not working, plus plenty of other new error messages are appearing, I don't think that isset() is a good "fix"
  28. #15
  29. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2002
    Location
    Seattle, U.S.A.
    Posts
    712
    Rep Power
    13
    Originally Posted by cssbonding
    I know that because somehow something isn't quite working on my localhost like it used too, search functions are not working, plus plenty of other new error messages are appearing, I don't think that isset() is a good "fix"
    Actually adding isset or !empty IS the right fix. I bet that your application always had these warnings and I bet if you fixed them it would start working. If you don't want to fix the warnings then you can either add in

    PHP Code:
    error_reporting(0); 
    See this page for help on this:
    http://php.net/manual/en/function.error-reporting.php

    To the top of your pages or you can do it globally by editing your php.ini file:

    Code:
    display_errors = Off
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo