Discuss Error messages: PHP in the PHP Development forum on Dev Shed. Error messages: PHP PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
Posts: 54
Time spent in forums: 10 h 47 m 10 sec
Reputation Power: 9
PHP5 - 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
Quote:
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
Posts: 1,882
Time spent in forums: 1 Month 2 Weeks 2 Days 9 h 58 m 26 sec
Reputation Power: 813
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.
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.
Posts: 1,882
Time spent in forums: 1 Month 2 Weeks 2 Days 9 h 58 m 26 sec
Reputation Power: 813
Quote:
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.
Quote:
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 05:40 AM.
Posts: 1,882
Time spent in forums: 1 Month 2 Weeks 2 Days 9 h 58 m 26 sec
Reputation Power: 813
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 07:24 AM.
Posts: 297
Time spent in forums: 3 Days 8 h 45 m 39 sec
Reputation Power: 5
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.
Posts: 54
Time spent in forums: 10 h 47 m 10 sec
Reputation Power: 9
Quote:
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
Posts: 297
Time spent in forums: 3 Days 8 h 45 m 39 sec
Reputation Power: 5
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.
Posts: 1,882
Time spent in forums: 1 Month 2 Weeks 2 Days 9 h 58 m 26 sec
Reputation Power: 813
Quote:
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().
Posts: 297
Time spent in forums: 3 Days 8 h 45 m 39 sec
Reputation Power: 5
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.
Posts: 712
Time spent in forums: 4 Days 11 h 4 m 59 sec
Reputation Power: 11
Quote:
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.
Posts: 54
Time spent in forums: 10 h 47 m 10 sec
Reputation Power: 9
Quote:
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"
Posts: 712
Time spent in forums: 4 Days 11 h 4 m 59 sec
Reputation Power: 11
Quote:
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