![]() |
|
[PHP] Undefined Variable Error - All Variables Defined - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183) +---- Thread: [PHP] Undefined Variable Error - All Variables Defined (/showthread.php?tid=5919660) |
Undefined Variable Error - All Variables Defined - Effexion - Dec 16, 2018 PHP Code ![]() Pprobably something stupid. This is the second time doing this section as I got this error with a third variable '$id' much later down the line. I tried to fix it and I messed everything up lol. I never got these errors here first time around. I thought I would ask you guys rather than making the same mistake I did last time. That looks fine to me and the HTML attributes are named as such. RE: Undefined Variable Error - All Variables Defined - Abruptum - Dec 16, 2018 (Dec 16, 2018 11:24 AM)That Guy with Spiders Wrote: you should do it like this : PHP Code it means that the post variable is not set, so you need to check it before using it. RE: Undefined Variable Error - All Variables Defined - Nachfolger - Dec 16, 2018 (Dec 16, 2018 11:39 AM)Abruptum Wrote: you should do it like this :Well yes, that's a proper way to validate it, but it still doesn't solve OP's problem OP, you need to check the HTML, not PHP. Make sure you have the "name=" attributes set inside your form on the username and password input boxes. If you're making a login system, tutorial or not, before you can even comprehend basic errors like this, you're setting yourself up for failure. RE: Undefined Variable Error - All Variables Defined - Effexion - Dec 16, 2018 When I click the button, the errors go. I kind of see what's happening here. The variables are only being set when I click the button. I guessed I needed to write them outside of the if, but that just threw more errors lol. RE: Undefined Variable Error - All Variables Defined - Abruptum - Dec 16, 2018 (Dec 16, 2018 11:55 AM)Nachfolger Wrote: Well yes, that's a proper way to validate it, but it still doesn't solve OP's problem. i think his problem is related to the issue that he serves the form on the bottom of his script so he will get the error when he visits the page the first time. If this is not your problem then you should check the form method and the input names. RE: Undefined Variable Error - All Variables Defined - Nachfolger - Dec 16, 2018 (Dec 16, 2018 11:55 AM)That Guy with Spiders Wrote: When I click the button, the errors go. I kind of see what's happening here. The variables are only being set when I click the button. I guessed I needed to write them outside of the if, but that just threw more errors lol.Oh, your PHP is on the same page as the form? Yes, you're trying to access them before they were even sent. You should still take heed to the advice in the latter portion of my previous post. RE: Undefined Variable Error - All Variables Defined - Effexion - Dec 16, 2018 (Dec 16, 2018 11:57 AM)Nachfolger Wrote: Oh, your PHP is on the same page as the form? Yes, you're trying to access them before they were even sent. You should still take heed to the advice in the latter portion of my previous post. I have checked it all over an made sure the names were there. This is something I checked: PHP Code RE: Undefined Variable Error - All Variables Defined - Abruptum - Dec 16, 2018 (Dec 16, 2018 01:08 PM)That Guy with Spiders Wrote: I have checked it all over an made sure the names were there. This is something I checked:There is no problem with your html code, you just request for post variables at the page call where are no such data. So you must check for existing of them before using them . Like Nachfolger allready mentioned don't do a login system if you have no clue how to do it, stick to the basics and do none security related stuff in the first base. RE: Undefined Variable Error - All Variables Defined - Effexion - Dec 16, 2018 (Dec 16, 2018 01:26 PM)Abruptum Wrote: There is no problem with your html code, you just request for post variables at the page call where are no such data. So you must check for existing of them before using them . I am on a course that has me doing this. It's simply a demonstration of communicating with a database. RE: Undefined Variable Error - All Variables Defined - Abruptum - Dec 16, 2018 (Dec 16, 2018 01:28 PM)That Guy with Spiders Wrote: I am on a course that has me doing this. It's simply a demonstration of communicating with a database. OK, then i have a advice which may be sound like i am a dick --> use google. Copy and paste the error and understand the basics why this wont work. There is no sense in creating thousands of threads for basic question which can be solved by fixing one line. RE: Undefined Variable Error - All Variables Defined - Effexion - Dec 16, 2018 Found my problem. I had missed a '}' in the if. Works fine now 🙂. RE: Undefined Variable Error - All Variables Defined - gigajew - Dec 16, 2018 Don't know if I'm late but your code in the op basically translates to Code if(isset($_POST['submit'])) {So it makes perfect sense that username is not defined RE: Undefined Variable Error - All Variables Defined - Effexion - Dec 16, 2018 (Dec 16, 2018 04:51 PM)gigajew Wrote: Don't know if I'm late but your code in the op basically translates to Care to elaborate? RE: Undefined Variable Error - All Variables Defined - gigajew - Dec 16, 2018 Yes, you had a one-line if in the beginning, thus covering only the first statement after it. |