Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Adam Smallman
94 PointsNeed help simple php login
Learning php and to test out some new things I wanted to create a simple logIn, but its not working can anyone see the problem??
( <!DOCTYPE html> <html> <head> <title>CITYlife.com</title> <meta charset="UTF-8"> <link rel="stylesheet" href="css/reset.css" > <link rel="stylesheet" href="css/text.css" > <link rel="stylesheet" href="css/stylesheet.css">
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script>
$(document).ready(function(){
$(".one").click(function(){ $(".finish").fadeOut();
}); });
</script>
</head> <body>
<div class="wrap">
<h1>password creator TEST!</h1>
<form action="#" method="get">
<label for="password">password</label>
<input type="text" id="password" name="password">
<input type="submit" value="done">
</form>
<?php
$pass = $_GET['password'];
print"$pass";
?>
<form action="#" method="get">
<label for="fpassword">password</label>
<input type="text" id="password" name="fpassword">
<input type="submit" value="done">
</form>
<?php
$fpass = $_GET['fpassword'];
if($fpass == $pass){
print"you got it!!";
}
?>
</div> <!-- END wrapper -->
</body>
</html>
)
3 Answers
Aaron Graham
18,033 Pointscould be that you have two 'id="password"' statements.
try changing:
<form action="#" method="get">
<label for="fpassword">password</label>
<input type="text" id="password" name="fpassword">
<input type="submit" value="done">
</form>
to:
<form action="#" method="get">
<label for="fpassword">password</label>
<input type="text" id="fpassword" name="fpassword">
<input type="submit" value="done">
</form>
thomascawthorn
22,986 PointsHi Aaron Graham , I'm wanting to learn about cookies and sessions in greater detail - can't find any treehouse material atm - can I ask how you learned how to use them properly?
Aaron Graham
18,033 PointsThomas Cawthorn, I picked up what I know through extensive use of php.net, w3schools.com, and plenty of googling. Here are a few good places to start:
http://www.w3schools.com/php/php_sessions.asp
http://www.w3schools.com/php/php_cookies.asp
http://www.php.net/manual/en/book.session.php
http://www.php.net/manual/en/features.cookies.php
Hope that helps.
thomascawthorn
22,986 PointsNice one, thanks!!
Aaron Graham
18,033 PointsAlso, if you haven't already, I would strongly suggest learning a framework. It can really make a lot of this stuff easy. I spent a lot of time early on coding things like database abstraction layers, and other such things, that are built into most frameworks. You don't have to spend the time doing it yourself and you don't have to worry as much about whether or not you are building things in a secure/best practice manner. I am currently using the Zend Framework and really like it, but I hear good things about CakePHP and CodeIgniter as well. Zend had a bit of a learning curve, but once you get the concepts, it is much faster from start to production ready code. Just thought I would pass that along in hopes of saving you some time in the future.
- cheers!
thomascawthorn
22,986 PointsReally cool! I'm just about to really start looking into laravel - I think there's a laravel track launching soon, which is handy! The reason I didn't use it for this project is because I don't have access to the server root file, only the public_html directory. From what I've read, it's best to split the laravel framework between the root and public areas? Although I could be very much mistaken!
Zend sounds awesome, I'll look into it :-)
But yeah, totally agree frameworks are the way forward. I'd just like to give it a go atleast once or twice to better understand the concepts behind ;)
Adam Smallman
94 PointsAdam Smallman
94 PointsThanks for your help but that didn't work.
If I dont give the user the ability to add there own password and lets say I give the $password variable = to 1 then when I enter 1 in the password area it works. But I want to give the user the ability to pick a password.
Aaron Graham
18,033 PointsAaron Graham
18,033 PointsI think it might be that you are entering the passwords in two different forms. You can only submit one form at a time. Try adding both password inputs to one form.
If you want to use one form to add a password and another to check the password, you will need to persist the password value in a session or a cookie.
Also, I feel obligated to add that using GET to submit passwords is probably not a great idea. You will want to use POST and probably set the "input" type to "password". I realize that this is for testing and you probably already understand this, but just in case, I thought I would mention it.