cabbie Posted March 27, 2013 Share Posted March 27, 2013 In trying to program a register login site I have tried every combo possible. Even with simple code the username is not passed to the login page IE echo $username yields nothiing . What would cause this? Actual link to try. In test database ollie & cab1234 are valid,, http://libertarian-forum.com/sim/login.php Codes: <form action = "loginscript.php" method = "post"> Username : <input type = "text" name = "username"> Password : <input type = "password" name = "password"> $username = $_POST['username']; echo $username; <input type = "submit" value = "Login"> </form> <?php include 'main.php'; include 'connect.php'; $username = $_POST['username']; echo $username; $password = md5($_POST['password']); $query = mysql_query("SELECT id,username, password FROM users WHERE username = '$username'"); if(!$query) echo "There is no such user with the entered username"; else{ $details = mysql_fetch_assoc($query); $usr = $details['username']; $pass = $details['password']; $id = $details['id']; if($pass == $password){ $_SESSION['id'] = $id; header("Location: loggedin.php"); } else echo "The username and password combination does not match"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/276228-registerlogin/ Share on other sites More sharing options...
Maq Posted March 27, 2013 Share Posted March 27, 2013 cabbie, please be conscious of what section you are posting in, this is the wrong one. Moving to PHP Help. Quote Link to comment https://forums.phpfreaks.com/topic/276228-registerlogin/#findComment-1421440 Share on other sites More sharing options...
davidannis Posted March 27, 2013 Share Posted March 27, 2013 if you comment out the includes does it still not echo? Quote Link to comment https://forums.phpfreaks.com/topic/276228-registerlogin/#findComment-1421442 Share on other sites More sharing options...
cabbie Posted March 27, 2013 Author Share Posted March 27, 2013 Sorry Maq With the condition of this Nation I am very political active and when I am wasting time on a simple problem I need a quick answer. This was a quick join the forum and post. Also at the time I had several issue on this old senile mind LOL Yes with the includes commented out it gives the same result.. Quote Link to comment https://forums.phpfreaks.com/topic/276228-registerlogin/#findComment-1421446 Share on other sites More sharing options...
davidannis Posted March 27, 2013 Share Posted March 27, 2013 I just cut and pasted your code, commented out the two includes, added a print_r($_POST) ran it on my local machine and I get the expected results: Array ( [username] => davidannis [password] => test ) davidannisThere is no such user with the entered username try print_r($_POST); before and after the includes. Quote Link to comment https://forums.phpfreaks.com/topic/276228-registerlogin/#findComment-1421452 Share on other sites More sharing options...
cabbie Posted March 27, 2013 Author Share Posted March 27, 2013 Thanks ..it works before and after the includes.. Quote Link to comment https://forums.phpfreaks.com/topic/276228-registerlogin/#findComment-1421459 Share on other sites More sharing options...
davidannis Posted March 27, 2013 Share Posted March 27, 2013 So, after the include print_r($_POST) shows a value in $_POST['username'] but you can not echo it with? $username = $_POST['username']; echo $username; FWIW: you should salt (add some unique per user characters) the password and use a more up to date function than md5. Anyone else have any ideas on the inability to echo the username? Quote Link to comment https://forums.phpfreaks.com/topic/276228-registerlogin/#findComment-1421460 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.