I have created a login system with some validation which all works fine, however I want to be able to create a session when the user logs in and then store this session information in a table that I have allready created.
The table has the following values
id
ip_address
session_id
user_id (the user id is stored in a table called 'user'

the login page which processes the users login and redirects the user to the members page is..

<?php
include'database_conn.php';//connect to the database
if(isset($_COOKIE['ID_my_site']))//checks if there is a login cookie
	{
		$username = $_COOKIE['ID_my_site'];//if there is a cookie it logs you in and directs you to the  page
		$pass = $_COOKIE['Key_my_site'];
		$check = mysql_query("SELECT * FROM users WHERE email = '$email'")or die(mysql_error());
		while($info = mysql_fetch_array( $check ))
		{
			if ($pass != $info['password'])
			{
			}
			else
			{
				header("Location:../site/members.php");
			}
		}
	}
if (isset($_POST['submit'])) {//runs if form has been submitted
	if(!$_POST['email'] | !$_POST['pass']) {//makes sure the user has filled the form in
		die('You did not fill in a required field.');
	}
	if (!get_magic_quotes_gpc()) {
		$_POST['email'] = addslashes($_POST['email']);//checks the form against the database
	}
	$check = mysql_query("SELECT * FROM users WHERE email = '".$_POST['email']."'")or die(mysql_error());//gives error is user doesnt exsist
	$check2 = mysql_num_rows($check);
	if ($check2 == 0) {
		die('That user does not exist in our database. <a href=../site/register.php>Click Here to Register</a>');
	}
	while($info = mysql_fetch_array( $check ))
	{
	$_POST['pass'] = stripslashes($_POST['pass']);
	$info['password'] = stripslashes($info['password']);
	$_POST['pass'] = md5($_POST['pass']);

	if ($_POST['pass'] != $info['password']) {//gives error if the password is wrong
		die('Incorrect password, please try again.');
	}
	else {
		
	$_POST['email'] = stripslashes($_POST['email']);//if login is ok we add a cookie
	$hour = time() + 3600;
	setcookie(ID_my_site, $_POST['email'], $hour);
	setcookie(Key_my_site, $_POST['pass'], $hour);
		
	header("Location:../login/process.members.php");//else redirect them to  area
			}
		}
	}
?>

Any help with adding the session to the mySQL table would be greatly appreciated

after

<?php session_start(); ?>

You will get a session id like

<?php echo $SID = session_id(); ?>

Then use the normal mysql_query() function to insert data to the database like

<?php
mysql_query("INSERT INTO `table_name`(`column_list`) values('$SID', 'other_values')")
?>

I believe that the mysql_query() should not have `` quotes at all.

Did you ever figure out that you needed another table to be created so that you could add column data to be associated?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.