Rifts Posted October 5, 2009 Share Posted October 5, 2009 Hey guys, I'm pretty new to php.. I downloaded a little php login form.. but its not working. when i hit submit instead of going to the members-index.php site it just reloads the normal index and changes the url bar to this http://localhost/homepage/?user=admin&password=pass&Submit=Login# i'm not really sure what other information to give you... let me know what else you need thanks Link to comment https://forums.phpfreaks.com/topic/176532-new-to-php-login-doesnt-work/ Share on other sites More sharing options...
Bricktop Posted October 5, 2009 Share Posted October 5, 2009 Hi rifts, Post your code so we can give a more definitive answer. Link to comment https://forums.phpfreaks.com/topic/176532-new-to-php-login-doesnt-work/#findComment-930563 Share on other sites More sharing options...
Rifts Posted October 5, 2009 Author Share Posted October 5, 2009 ok here is the login form code in my index.html <center> <div id="login"> <form id="loginForm" method="post" action="login-exec.php"> Client ID: <br /><input type="text" class="theInput" name="user" /> <br /> Password: <br /><input type="password" class="theInput" name="password" /> <br /> <input type="submit" name="Submit" class="theSubmit" value="Login" /> </form> </center> and here is the login-exec.php (I think when I hit submit its not "activating" the login-exec.php) <?php //Start session session_start(); //Include database connection details require_once('config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $login = clean($_POST['login']); $password = clean($_POST['password']); //Input Validations if($login == '') { $errmsg_arr[] = 'Login ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } //If there are input validations, redirect back to the login form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: login-form.php"); exit(); } //Create query $qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'"; $result=mysql_query($qry); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) == 1) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['member_id']; $_SESSION['SESS_FIRST_NAME'] = $member['firstname']; $_SESSION['SESS_LAST_NAME'] = $member['lastname']; session_write_close(); header("location: http://localhost/homepage/member-index.php"); exit(); }else { //Login failed header("location: login-failed.php"); exit(); } }else { die("Query failed"); } ?> thanks lemme know what else you might need Link to comment https://forums.phpfreaks.com/topic/176532-new-to-php-login-doesnt-work/#findComment-930568 Share on other sites More sharing options...
d.shankar Posted October 5, 2009 Share Posted October 5, 2009 The variable names are different from the one use in the login-exec.php file This should be $login = clean($_POST['user']); $password = clean($_POST['password']); Link to comment https://forums.phpfreaks.com/topic/176532-new-to-php-login-doesnt-work/#findComment-930574 Share on other sites More sharing options...
Rifts Posted October 5, 2009 Author Share Posted October 5, 2009 Ok I just changed that variable in the login-exec.php and its still not working? Link to comment https://forums.phpfreaks.com/topic/176532-new-to-php-login-doesnt-work/#findComment-931137 Share on other sites More sharing options...
Rifts Posted October 6, 2009 Author Share Posted October 6, 2009 bump Link to comment https://forums.phpfreaks.com/topic/176532-new-to-php-login-doesnt-work/#findComment-931262 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.