jurass1c Posted April 7, 2010 Author Share Posted April 7, 2010 <form name="form" id="form" class="form" action="insert.php" method="post"> <tr> <td width="89" height="27" align="left" valign="middle"> Album Cover: </td> <td width="308" align="left" valign="middle"> <input name="cover" type="text" size="40" /> *</td> <td width="253" rowspan="9" align="center" valign="middle"> </td> </tr> <tr> <td height="28" align="left" valign="middle"> Album:</td> <td align="left" valign="middle"><input name="album" type="text" size="40" /> *</td> </tr> <tr> <td height="29" align="left" valign="middle"> Artist: </td> <td align="left" valign="middle"><input name="artist" type="text" size="40" /> *</td> </tr> <tr> <td height="29" align="left" valign="middle"> Album Year: </td> <td align="left" valign="middle"><select name="album_year"> <option value="">Unkown</option> <option value="2010">2010</option> <option value="2009">2009</option> <option value="2008">2008</option> <option value="2007">2007</option> <option value="2006">2006</option> <option value="2005">2005</option> <option value="2004">2004</option> <option value="2003">2003</option> <option value="2002">2002</option> <option value="2001">2001</option> <option value="2000">2000</option> <option value="1999">1999</option> <option value="1998">1998</option> <option value="1997">1997</option> <option value="1996">1996</option> <option value="1995">1995</option> <option value="1994">1994</option> <option value="1993">1993</option> <option value="1992">1992</option> <option value="1991">1991</option> <option value="1990">1990</option> </select> *</td> </tr> <tr> <div align="right"><input type="submit" class="btn" value="Share" /></div> <br /> <br /> <br /></td> </tr> </form> Link to comment https://forums.phpfreaks.com/topic/196800-capturing-username/page/2/#findComment-1038244 Share on other sites More sharing options...
Potatis Posted April 7, 2010 Share Posted April 7, 2010 That doesn't look like a login form to me. Link to comment https://forums.phpfreaks.com/topic/196800-capturing-username/page/2/#findComment-1038247 Share on other sites More sharing options...
jurass1c Posted April 7, 2010 Author Share Posted April 7, 2010 sorry guys lol. <fieldset id="signin_menu"> <form method="post" id="signin" action="indxlog.php" name="login"> <label for="username">Username or email</label> <input name="usr_email" id="name" class="required" value="" title="username" tabindex="4" type="text"> </p> <p> <label for="password">Password</label> <input id="password "name="pwd" class="required password" value="" title="password" tabindex="5" type="password"> </p> <p class="remember"> <input id="signin_submit" value="Sign in" tabindex="6" type="submit"> <input id="remember" name="remember" value="1" tabindex="7" type="checkbox"> <label for="remember">Remember me</label> </p> <p class="forgot"> <a href="#" id="resend_password_link">Forgot your password</a> </p> <p class="forgot-username"> <A id=forgot_username_link title="Activation code will be required" href="#">Activate Account</A> </p> </form> </fieldset> Link to comment https://forums.phpfreaks.com/topic/196800-capturing-username/page/2/#findComment-1038249 Share on other sites More sharing options...
Wolphie Posted April 7, 2010 Share Posted April 7, 2010 <input name="usr_email" id="name" class="required" value="" title="username" tabindex="4" type="text"> There's your problem. The name attribute is "usr_email". "user_name" doesn't exist in the POST array. Link to comment https://forums.phpfreaks.com/topic/196800-capturing-username/page/2/#findComment-1038263 Share on other sites More sharing options...
jurass1c Posted April 7, 2010 Author Share Posted April 7, 2010 No luck there here is what i use in the usr_email variable { $user_email = mysql_real_escape_string($_POST['usr_email']); $md5pass = md5(mysql_real_escape_string($_POST['pwd'])); if (strpos($user_email,'@') === false) { $user_cond = "user_name='$user_email'"; } else { $user_cond = "user_email='$user_email'"; } so the user can either log in by email or username. This is the session code // this sets session and logs user in session_start(); // this sets variables in the session $_SESSION['user_id']= $id; $_SESSION['user_name']= $_POST['user_name']; //set a cookie witout expiry until 60 days if(isset($_POST['remember'])){ setcookie("user_id", $_SESSION['user_id'], time()+60*60*24*60, "/"); //60 sec * 60 min * 24 hours * 60 days setcookie("user_name", $_SESSION['user_name'], time()+60*60*24*60, "/"); //60 sec * 60 min * 24 hours * 60 days } header("Location: account.php"); } else { $msg = urlencode("Invalid Login. Please try again with correct user email and password. "); header("Location:login.php?msg=$msg"); } I use this code to protect pages and start sessions. ******************** PAGE PROTECT CODE ***************/ function page_protect() { session_start(); //check for cookies if(isset($_COOKIE['user_id']) && isset($_COOKIE['user_name'])){ $_SESSION['user_id'] = $_COOKIE['user_id']; $_SESSION['user_name'] = $_COOKIE['user_name']; } if (!isset($_SESSION['user_id'])) { header("Location: login.php"); } /******************************************************/ } So i use this variable $_SESSION[user_name] in the file that insert's content and i want to capture and post the username in this below file <?php include 'db.php'; page_protect(); $user_ip = $_SERVER['REMOTE_ADDR']; $sql="INSERT INTO example (cover, album, artist, date, users_ip, user_name, album_year) VALUES ('$_POST[cover]','$_POST[album]','$_POST[artist]', now(), '$user_ip', '$_SESSION[user_name]', '$_POST[album_year]')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } header("Location: share.php"); exit(); ?> where am i going wrong ? Link to comment https://forums.phpfreaks.com/topic/196800-capturing-username/page/2/#findComment-1038322 Share on other sites More sharing options...
zeodragonzord Posted April 7, 2010 Share Posted April 7, 2010 You use $_POST to get the form values from the previous page. I noticed that on your login form, the action is set to indxlog.php. However, you're using check.php to look for the $_POST form values from the login page. The indxlog.php will need to get the $_POST values. If you do a var_dump($_POST) in indxlog.php, you should see the form values there. The indxlog.php page should be the one to check if the username is valid and then set it to the $_SESSION if valid. Link to comment https://forums.phpfreaks.com/topic/196800-capturing-username/page/2/#findComment-1038618 Share on other sites More sharing options...
jurass1c Posted April 8, 2010 Author Share Posted April 8, 2010 finally worked this one out guys. thanks for all your help !! especially zeodragonzord Link to comment https://forums.phpfreaks.com/topic/196800-capturing-username/page/2/#findComment-1038797 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.