netman182 Posted December 10, 2009 Share Posted December 10, 2009 i am having a problem with a variable and turning it into a session. i don't want a code re-write or anything like that but something i might be doing wrong. I am trying to get `teamid` a session variable. I have included code. i know it is not working because i am trying to echo it on the next page to see if it is working.' <?php include 'db_conn.php'; if ($_POST['doLogin']=='Login') { $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'"; } $sql = "SELECT `id`,`full_name`,`approved`,`teamid` FROM managers WHERE $user_cond AND `pwd` = '$md5pass' AND `banned` = '0' "; $result = mysql_query($sql) or die (mysql_error()); $num = mysql_num_rows($result); // Match row found with more than 1 results - the user is authenticated. if ( $num > 0 ) { list($id,$full_name,$approved) = mysql_fetch_row($result); if(!$approved) { $msg = "Account not activated. Please check your email for activation code"; header("Location: login.php?msg=$msg"); exit(); } // this sets session and logs user in session_start(); // this sets variables in the session $_SESSION['user_id']= $id; $_SESSION['user_name'] = $full_name; $_SESSION['teamid'] = $teamid; //set a cookie witout expiry until 60 days if(isset($_POST['remember'])){ setcookie("user_id", $_SESSION['user_id'], time()+60*60*24*60, "/"); setcookie("user_name", $_SESSION['user_name'], time()+60*60*24*60, "/"); } header("Location: myaccount.php"); } else { $msg = urlencode("Invalid Login. Please try again with correct user email and password. "); header("Location: login.php?msg=$msg"); } } ?> <html> <head> <title>Members Login</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript" type="text/javascript" src="js/jquery-1.3.2.min.js"></script> <script language="JavaScript" type="text/javascript" src="js/jquery.validate.js"></script> <script> $(document).ready(function(){ $("#logForm").validate(); }); </script> <link href="styles.css" rel="stylesheet" type="text/css"> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="5" class="main"> <tr> <td colspan="3"> </td> </tr> <tr> <td width="160" valign="top"><p> </p> <p> </p> <p> </p> <p> </p> <p> </p></td> <td width="732" valign="top"><p> </p> <h3 class="titlehdr">Login Users </h3> <p> <? /******************** ERROR MESSAGES************************************************* This code is to show error messages **************************************************************************/ if (isset($_GET['msg'])) { $msg = mysql_real_escape_string($_GET['msg']); echo "<div class=\"msg\">$msg</div>"; } /******************************* END ********************************/ ?></p> <form action="login.php" method="post" name="logForm" id="logForm" > <table width="65%" border="0" cellpadding="4" cellspacing="4" class="loginform"> <tr> <td colspan="2"> </td> </tr> <tr> <td width="28%">Username / Email</td> <td width="72%"><input name="usr_email" type="text" class="required" id="txtbox" size="25"></td> </tr> <tr> <td>Password</td> <td><input name="pwd" type="password" class="required password" id="txtbox" size="25"></td> </tr> <tr> <td colspan="2"><div align="center"> <input name="remember" type="checkbox" id="remember" value="1"> Remember me</div></td> </tr> <tr> <td colspan="2"> <div align="center"> <p> <input name="doLogin" type="submit" id="doLogin3" value="Login"> </p> <p><a href="register.php">Register Free</a><font color="#FF6600"> |</font> <a href="forgot.php">Forgot Password</a> <font color="#FF6600"> |</font> <a href="activate.php">Activate Account</a></p> </div></td> </tr> </table> <div align="center"></div> <p align="center"> </p> </form> <p> </p> </td> <td width="196" valign="top"> </td> </tr> <tr> <td colspan="3"> </td> </tr> </table> </body> </html> Link to comment https://forums.phpfreaks.com/topic/184606-session-varaible-problem/ Share on other sites More sharing options...
BenInBlack Posted December 10, 2009 Share Posted December 10, 2009 looks like your call to "session_start();" is embedded in if logic that prevents it from being invoked for all path that need it. I alway put it at the top prior to any logic Link to comment https://forums.phpfreaks.com/topic/184606-session-varaible-problem/#findComment-974553 Share on other sites More sharing options...
netman182 Posted December 10, 2009 Author Share Posted December 10, 2009 i actually did it on my own. i looked at BenInBlack's suggestion. and looked closer at it. i then realized i overlooked : list($id,$full_name,$approved) = mysql_fetch_row($result); I then noticed i overlooked put in teamid list($id,$full_name,$approved,$teamid) = mysql_fetch_row($result); thanks Link to comment https://forums.phpfreaks.com/topic/184606-session-varaible-problem/#findComment-974562 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.