fbm Posted March 2, 2009 Share Posted March 2, 2009 hi, I am working on a login page for my system. I have a DB all setup which holds client details including the Username and Password. I have this on my login page <?php session_start();?> <?php include "includes/header.php"; ?> <div id="page_content"> <div id="sub_menu"></div> <div id="content"> <h1>Welcome</h1> <form action="processlogin.php" method="POST"> <table cellspacing="10"> <tr><td><p>User ID:</td><td><input class="box" type="text" name="username"></td></tr> <tr><td><p>Password:</td><td><input class="box" type="password" name="password"></td></tr> <tr><td colspan="2"><input type="submit" value="Login"></td></tr> </table> </form> </div> </div> <?php include "includes/footer.php"; ?> header includes the config.php file and DB connection is all workign fine I then have this on my processlogin.php page <?php $username = $_POST["username"]; $password = $_POST["password"]; include "includes/config.php"; $sql="SELECT * FROM clients WHERE username='$username' and password='$password'"; $r = mysql_query($sql); if(!$r) { $err=mysql_error(); print $err; exit(); } if(mysql_affected_rows()==0){ echo "<p>The username or password you have entered is incorrect!</p>"; echo "<META HTTP-EQUIV=Refresh CONTENT='4; URL=index.php'> "; exit(); } else{ $_SESSION["username"] = $username; echo "<div align='center'><h5>Logging In</h5></div>"; echo "<META HTTP-EQUIV=Refresh CONTENT='2; URL=client_home.php'> "; } ?> i then have this on my landing page after log in is processed <?php session_start();?> <?php include "includes/header.php"; ?> <div id="page_content"> <div id="sub_menu"></div> <div id="content"> <h1>Welcome back <?php echo $_SESSION['username'];?></h1> </div> </div> <?php include "includes/footer.php"; ?> after logging in i get the following error Notice: Undefined index: username in C:\wamp\www\fbmcrm\clients\client_home.php on line 6 i think the username is not being passed properly in the session. I am trying to acheive a landing page which simply generates a welcome message saying welcome back (username) to start with and the username is specific to the login details used. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/147652-solved-processing-login-and-using-session-to-hold-data/ Share on other sites More sharing options...
premiso Posted March 2, 2009 Share Posted March 2, 2009 You do not have session_start on the page that does the processing. Quote Link to comment https://forums.phpfreaks.com/topic/147652-solved-processing-login-and-using-session-to-hold-data/#findComment-775112 Share on other sites More sharing options...
fbm Posted March 2, 2009 Author Share Posted March 2, 2009 cool thanks, now works and shows the Username on login now how do i add other Client data to the session such as the client id? Quote Link to comment https://forums.phpfreaks.com/topic/147652-solved-processing-login-and-using-session-to-hold-data/#findComment-775116 Share on other sites More sharing options...
premiso Posted March 2, 2009 Share Posted March 2, 2009 if(mysql_num_rows() < 1){ echo "<p>The username or password you have entered is incorrect!</p>"; echo "<META HTTP-EQUIV=Refresh CONTENT='4; URL=index.php'> "; exit(); } else{ $data = mysql_fetch_assoc($r); $_SESSION["username"] = $username; $_SESSION['clientid'] = $data['clientid']; // given that the col name from mysql is that // more data set here echo "<div align='center'><h5>Logging In</h5></div>"; echo "<META HTTP-EQUIV=Refresh CONTENT='2; URL=client_home.php'> "; } ?> Just like that.... Quote Link to comment https://forums.phpfreaks.com/topic/147652-solved-processing-login-and-using-session-to-hold-data/#findComment-775120 Share on other sites More sharing options...
fbm Posted March 2, 2009 Author Share Posted March 2, 2009 thanks again works great Quote Link to comment https://forums.phpfreaks.com/topic/147652-solved-processing-login-and-using-session-to-hold-data/#findComment-775126 Share on other sites More sharing options...
fbm Posted March 2, 2009 Author Share Posted March 2, 2009 now trying to get the full client info from teh DB on teh landing page. Here is the full landing page <?php session_start();?> <?php include "includes/header.php"; ?> <div id="page_content"> <div id="sub_menu"></div> <div id="content"> <h1>Welcome back <?php echo $_SESSION['username'];?></h1> <?php $result = mysql_query("SELECT * FROM clients WHERE `id` = '".$_GET['id']."'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { ?> <div id="add_client_box"> <h1>Account Details</h1> <table width="404" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="left">Company : </td> <td class="right"><?php echo $row['company'];?></td> </tr> <tr> <td class="left">Account No : </td> <td class="right"><?php echo $row['account_number'];?></td> </tr> <tr> <td class="left">Website : </td> <td class="right"><?php echo $row['website'];?></td> </tr> </table> </div> <div id="add_client_box"> <h1>Company Address</h1> <table width="404" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="left">Building Number : </td> <td class="right"><?php echo $row['building_number'];?></td> </tr> <tr> <td class="left">Street : </td> <td class="right"><?php echo $row['street'];?></td> </tr> <tr> <td class="left">City : </td> <td class="right"><?php echo $row['city'];?></td> </tr> <tr> <td class="left">County : </td> <td class="right"><?php echo $row['county'];?></td> </tr> <tr> <td class="left">Post Code : </td> <td class="right"><?php echo $row['post_code'];?></td> </tr> </table> </div> <div id="add_client_box"> <h1>Primary Contact</h1> <table width="404" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="left">Primary Contact : </td> <td class="right"><?php echo $row['primary_contact'];?></td> </tr> <tr> <td class="left">Primary Email : </td> <td class="right"><?php echo $row['primary_email'];?></td> </tr> <tr> <td class="left">Primary Phone : </td> <td class="right"><?php echo $row['primary_phone'];?></td> </tr> </table> </div> <div id="add_client_box"> <h1>Billing Contact</h1> <table width="404" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="left">Billing Contact : </td> <td class="right"><?php echo $row['billing_contact'];?></td> </tr> <tr> <td class="left">Billing Email : </td> <td class="right"><?php echo $row['billing_email'];?></td> </tr> <tr> <td class="left">Billing Phone : </td> <td class="right"><?php echo $row['billing_phone'];?></td> </tr> </table> </div> <div id="add_client_box"> <h1>User Credentials</h1> <table width="404" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="left">Username : </td> <td class="right"><?php echo $row['username'];?></td> </tr> <tr> <td class="left">Password : </td> <td class="right"><?php echo $row['password'];?></td> </tr> </table> </div> <div id="add_account_box"></div> </div> </div> <?php } ?> </div> </div> <?php include "includes/footer.php"; ?> I now get an undefined index again which i assume is because query is wrong or i need to add the ID from teh session somewhere on teh page so it knows what the ID is in the query. Any ideas? Cheers again Quote Link to comment https://forums.phpfreaks.com/topic/147652-solved-processing-login-and-using-session-to-hold-data/#findComment-775132 Share on other sites More sharing options...
fbm Posted March 2, 2009 Author Share Posted March 2, 2009 SOLVED : i changed the $_GET to $_SESSION in teh query and it gets the correct details based on teh ID which is passed in the session. Woohooo!!!! thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/147652-solved-processing-login-and-using-session-to-hold-data/#findComment-775134 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.