Jump to content

how to store session variable


SUNIL16

Recommended Posts

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");

:P

Link to comment
https://forums.phpfreaks.com/topic/116176-how-to-store-session-variable/
Share on other sites

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

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']'........

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.