SUNIL16 Posted July 23, 2008 Share Posted July 23, 2008 Hello, I am doing one job portal project. i created registration page which is successful and login authentication is also successful. I am having forum in that i want to take the username value from the login form and i want to send the username value to database when he is creating new topic. same like what i am posting a topic in this forum know like that. here when i post my topic it will take my username. This is how i am setting the session $sql="SELECT * FROM register WHERE username='$username' and password='$password'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_register("myusername"); session_register("mypassword"); include("sucess.php"); Link to comment https://forums.phpfreaks.com/topic/116176-how-to-store-session-variable/ Share on other sites More sharing options...
MasterACE14 Posted July 23, 2008 Share Posted July 23, 2008 Try this. <?php session_start(); $sql = "SELECT * FROM `register` WHERE `username`='$username' and `password`='$password'"; $result = mysql_query($sql) or die("Could not run the query: ".mysql_error()); $count = mysql_num_rows($result); if($count == 1) { $_SESSION["myusername"] = $username; $_SESSION["mypassword"] = $password; include("sucess.php"); } else { echo "There is no one by that username."; } ?> Regards ACE Link to comment https://forums.phpfreaks.com/topic/116176-how-to-store-session-variable/#findComment-597416 Share on other sites More sharing options...
unkwntech Posted July 23, 2008 Share Posted July 23, 2008 do this: session_start() //this MUST go at the top of the page $sql="SELECT * FROM register WHERE username='$username' and password='$password'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ $_SESSION['username'] = $username; include("sucess.php"); Then later when you want to use the data for your insert you will do this: session_start() //again BEFORE ANY output ... $sql = "INSERT INTO posts VALUES('', '$_SESSION['uername']'........ Link to comment https://forums.phpfreaks.com/topic/116176-how-to-store-session-variable/#findComment-597417 Share on other sites More sharing options...
SUNIL16 Posted July 24, 2008 Author Share Posted July 24, 2008 Thanks MasterACE14,can i able to get the username any where after he login. using $_SESSION["myusername"] Link to comment https://forums.phpfreaks.com/topic/116176-how-to-store-session-variable/#findComment-598665 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.