Hi,
I am a beginner to PHP, and have been learning through a training CD, but I didn’t realize until half way through that the original CD was compiled in 2002, and PHP has come a long way since then. I am running MAMP V1.7.1 using PHP V5, and am having a (more than a few) hiccups. I have been able to research and get fixes or workarounds for most things till now, which has boosted my confidence somewhat, but am really stuck on this one. I have got to the stage where I am trying to put together a really basic login page (very basic) as per the instruction CD.
Would really appreciate someone helping me with this, or maybe I just need to start again with a different way of writing it?
Here are a few errors that I am getting at this moment.
Login
Notice: Undefined index: logged_in_user in /Applications/MAMP/htdocs/login_password/login.php on line 26
We are sorry, invalid login, please try again (So it appears to me that the script is executing to this stage?)
Login
Notice: Undefined index: user in /Applications/MAMP/htdocs/login_password/login.php on line 22
Your UserName:
Your Password:
And here is the script I have been learning. I have added the $_POST to everything I can think of, and have also rather than writing them as I have on every part, tried putting them at the top of the script as variables pre defined, but keep getting tons of ‘Undefined Index errors’ when I do it this way. Yet when I have written it the way below, I just get the ones above.
<?php ob_start(); ?> Login PageLogin
<?php $links = "Click here to return to the main pageClick here to Log Out"; if ($user=$_POST["user"] && $pass=$_POST["pass"]) { if($logged_in_user=$_POST["logged_in_user"] == $user=$_POST["user"]) { print $user .", you are already logged in.
"; print $links; exit; } $db = mysql_connect("localhost:8888","????","????"); mysql_select_db("userlist", $db); $query = "SELECT * from users WHERE name = '".$user=$_POST["user"]."' AND password = PASSWORD('".$pass=$_POST["pass"]."')"; $result = mysql_query($query); if(!$result) { print "Sorry, there appears to be a technical hitch, and we are unable to log you in"; exit; } if (mysql_num_rows($result) > 0) { $logged_in_user=$_POST["logged_in_user"] = $user=$_POST["user"]; session_register("logged_in_user"); print "Welcome" .$logged_in_user=$_POST["logged_in_user"] ."
"; print $links; exit; } else { print "We are sorry, invalid login, please try again"; exit; } if (!$user=$_POST["user"] || !$pass=$_POST["user"]) { print "Please fill in both form fields.
"; exit; } } ?>
Your UserName:
Your Password:
Again, hoping someone can help.
Regards - Timberman.