PHP Code
<?php if(isset($_POST['submit'])) $username = $_POST['username']; $password = $_POST['password']; echo $username . " " . $password; ?>
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.
Dec 16, 2018 11:39 AM
(This post was last modified: Dec 16, 2018 11:40 AM by Abruptum.)
(Dec 16, 2018 11:24 AM)Effexion Wrote: PHP Code
<?php if(isset($_POST['submit'])) $username = $_POST['username']; $password = $_POST['password']; echo $username . " " . $password; ?>
![[Image: MtGwGUz.png]](https://i.imgur.com/MtGwGUz.png)
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.
you should do it like this :
PHP Code
<?php if(isset($_POST['submit']) && !empty($_POST['username']) && !empty($_POST['password'])){ $username = $_POST['username']; $password = $_POST['password']; echo $username . " " . $password; } ?>
it means that the post variable is not set, so you need to check it before using it.
Dec 16, 2018 11:55 AM
(This post was last modified: Dec 16, 2018 11:58 AM by Nachfolger.)
(Dec 16, 2018 11:39 AM)Abruptum Wrote: you should do it like this :
PHP Code
<?php if(isset($_POST['submit']) && !empty($_POST['username']) && !empty($_POST['password'])){ $username = $_POST['username']; $password = $_POST['password']; echo $username . " " . $password; } ?>
it means that the post variable is not set, so you need to check it before using it. 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.
Je t'aime
(Apr 22, 2022 04:39 PM)-Scrub Wrote: Jokes on you, I'm not smart enough to know what he's talking about.
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.
(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.
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.
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.
(Dec 16, 2018 11:55 AM)Effexion 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.
Je t'aime
(Apr 22, 2022 04:39 PM)-Scrub Wrote: Jokes on you, I'm not smart enough to know what he's talking about.
(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
<?php <body> <div class="container"> <div class="col-sm-6"> <form action="login.php" method="post"> <div class="form-group"> <label for="username">Username</label> <input type="text" name="username" class="form-control"> </div> <div class="form-group"> <label for="password">Password</label> <input type="password" name ="password" class="form-control"> </div> <input class ="btn btn-primary" type="Submit" name="submit" value="Submit" </form> </div> </div> </body>
(Dec 16, 2018 01:08 PM)Effexion Wrote: I have checked it all over an made sure the names were there. This is something I checked:
PHP Code
<?php <body> <div class="container"> <div class="col-sm-6"> <form action="login.php" method="post"> <div class="form-group"> <label for="username">Username</label> <input type="text" name="username" class="form-control"> </div> <div class="form-group"> <label for="password">Password</label> <input type="password" name ="password" class="form-control"> </div> <input class ="btn btn-primary" type="Submit" name="submit" value="Submit" </form> </div> </div> </body>
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.
(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 .
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.
I am on a course that has me doing this. It's simply a demonstration of communicating with a database.
(Dec 16, 2018 01:28 PM)Effexion 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.
Found my problem. I had missed a '}' in the if. Works fine now 🙂.
Don't know if I'm late but your code in the op basically translates to
Code if(isset($_POST['submit'])) {
$username = $_POST['username'];
}
$password = $_POST['password'];
echo $username . " " . $password;
So it makes perfect sense that username is not defined
(Dec 16, 2018 04:51 PM)gigajew Wrote: Don't know if I'm late but your code in the op basically translates to
Code if(isset($_POST['submit'])) {
$username = $_POST['username'];
}
$password = $_POST['password'];
echo $username . " " . $password;
So it makes perfect sense that username is not defined
Care to elaborate?
Yes, you had a one-line if in the beginning, thus covering only the first statement after it.
|