Rabastan Posted August 14, 2012 Share Posted August 14, 2012 Rather new to PHP but I am learning I have a simple login system for a website, and a table for users. user table has these fields; id firstname lastname email username password What I would like to do is store the first and last name in the session also in order to display "Welcome FIRSTNAME LASTNAME" on the site Code is as follows; main_login.php <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form name="form1" method="post" action="checklogin.php"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td colspan="3"><strong>Member Login </strong></td> </tr> <tr> <td width="78">Username</td> <td width="6">:</td> <td width="294"><input name="myusername" type="text" id="myusername"></td> </tr> <tr> <td>Password</td> <td>:</td> <td><input name="mypassword" type="text" id="mypassword"></td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" name="Submit" value="Login"></td> </tr> </table> checklogin.php $host="localhost"; // Host name $username="******"; // Mysql username $password="*****"; // Mysql password $db_name="*****"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); header("location:index.php"); } else { echo "Wrong Username or Password"; } ?> Any help is appreciated Thank You Ran Quote Link to comment https://forums.phpfreaks.com/topic/267088-storing-info-in-session/ Share on other sites More sharing options...
Pikachu2000 Posted August 15, 2012 Share Posted August 15, 2012 That code is from phpeasystep.com, and unfortunately most, if not all or the code on that site is outdated and shouldn't be used as a learning tool. Quote Link to comment https://forums.phpfreaks.com/topic/267088-storing-info-in-session/#findComment-1369470 Share on other sites More sharing options...
Rabastan Posted August 15, 2012 Author Share Posted August 15, 2012 What does it matter where I got the code from, this forum is entitled "PHP Coding HELP"!!! Which would lead one to assume its a place to go when you need help with PHP, NOT somewhere to go and get ridiculed about my php. If that is what I was looking for I would have gone to "Tease you because your not as good as I am" forum. Come on people grow the fuck up!! If your not interested in helping don't post, does it really make you feel better to put people down?? Rab Quote Link to comment https://forums.phpfreaks.com/topic/267088-storing-info-in-session/#findComment-1369471 Share on other sites More sharing options...
Mahngiel Posted August 15, 2012 Share Posted August 15, 2012 rofl. you're cute you never defined a question, just posted some code you lifted off an antiquated source. what do you want from us? Quote Link to comment https://forums.phpfreaks.com/topic/267088-storing-info-in-session/#findComment-1369472 Share on other sites More sharing options...
Rabastan Posted August 15, 2012 Author Share Posted August 15, 2012 Rather new to PHP but I am learning I have a simple login system for a website, and a table for users. user table has these fields; id firstname lastname email username password What I would like to do is store the first and last name in the session also in order to display "Welcome FIRSTNAME LASTNAME" on the site. Code is as follows; main_login.php Yah I am pretty sure that there pretty much explains what I am trying to do!! Rab Quote Link to comment https://forums.phpfreaks.com/topic/267088-storing-info-in-session/#findComment-1369474 Share on other sites More sharing options...
Mahngiel Posted August 15, 2012 Share Posted August 15, 2012 that's not a question. that's a statement. we don't write code for you, we help you with problems you have. so far, the only problem you have is using outdated code - to wit Pikachu tried to help you solve. Quote Link to comment https://forums.phpfreaks.com/topic/267088-storing-info-in-session/#findComment-1369476 Share on other sites More sharing options...
Pikachu2000 Posted August 15, 2012 Share Posted August 15, 2012 This forum is entitled "PHP Coding HELP"!!! Which would lead one to assume its a place to go when you need help with PHP, NOT somewhere to go and get ridiculed about my php. If that is what I was looking for I would have gone to "Tease you because your not as good as I am" forum. Come on grow the fuck up! Your a mod your tasked to maintain the integrity of this forum, you should be ashamed!! If your not interested in helping don't post, does it really make you feel better to put people down?? Rab In response to the above shitty PM you sent me when I was trying to alert you that the old code you COPIED AND PASTED from a crappy website was badly out of date, would you care to explain just how exactly my post is in any way "putting people down"? Just how do you think it is that I was able to recognize that code as being from phpeasystep.com so easily? Do you think it's because their code is perfect, and nobody ever posts it here with problems, or do you think it's because it gets posted here all the time and is constantly problematic? Quote Link to comment https://forums.phpfreaks.com/topic/267088-storing-info-in-session/#findComment-1369481 Share on other sites More sharing options...
jcbones Posted August 15, 2012 Share Posted August 15, 2012 Ah Pik, the `ole "stop trying to help me, but give me what I want" thread. You never win in this one. Back to the OP, the request you posted, has nothing to do with the code you posted. <?php session_start(); if(isset($_GET['name'])) { $name = $_GET['name']; $_SESSION['name'] = $_GET['name']; } elseif(isset($_SESSION['name'])) { $name = $_SESSION['name']; } else { $name = 'Guest'; } echo 'Welcome ' . $name; Quote Link to comment https://forums.phpfreaks.com/topic/267088-storing-info-in-session/#findComment-1369487 Share on other sites More sharing options...
Rabastan Posted August 15, 2012 Author Share Posted August 15, 2012 Pikachu, My apologies then, you came off to me as slamming me for using code from another site. If that was not the case I truly apologize. Rab Quote Link to comment https://forums.phpfreaks.com/topic/267088-storing-info-in-session/#findComment-1369494 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.