I am going crazy trying to learn how to use sessions to store values of custom fields in my registration_form.php so I can call the data on other pages. I have read all sorts of websites but nobody seems to explain where exactly I am supposed to put the code to capture the data. I have two custom registration fields I added to a script (bio and displayname). I tried inserting this code on the registration form at the top and bottom and also on a register.php (both scripts below).
Where does the code go to store these fields to a session? I know it is wrong below because at this point I have tried placing it everywhere in everyway I can....
//registration_form.php
<?php session_start();
$_SESSION['displayname'] = $displayname;
$_SESSION['bio'] = $bio;
$author = $_SESSION['displayname'];
$bio = $_SESSION['bio'];
?>
<HTML>
<head>
<title>Practice</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="css/style.css" rel="stylesheet" media="screen">
</head>
<body>
<script src="js/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/jquery.validate.js"></script>
<div class="logo">
<h2><?php include('db.php'); echo $logotxt; ?></h2>
</div>
<form class="form-horizontal" id="register_form" method="post">
<h2>Register</h2>
<div class="line"></div>
<div class="control-group">
<input type="text" id="inputEmail" name="email" placeholder="Email">
</div>
<div class="control-group">
<input type="text" id="inputuserid" name="username" placeholder="Username">
</div>
<div class="control-group">
<input type="text" id="displayname" name="displayname" placeholder="Display name">
</div>
<div class="control-group">
<textarea name="bio" class="textfield" id="bio" cols="25" rows="7" placeholder="Bio
(optional). Tell us about yourself."></textarea>
</div>
<button type="submit" class="btn btn-large btn-primary btn-sign-in" data-loading-
text="Loading...">Register</button>
<a href="index.php" class="btn btn-large btn-register">Sign in</a>
<div class="messagebox">
<div id="alert-message"></div>
</div>
</form>
<?php
// starting the session
session_start();
if (isset($_POST['Submit'])) {
$_SESSION['displayname'] = $displayname;
$_SESSION['bio'] = $bio;
}
?>
//register.php
<?php
include("db.php");
$con=mysql_connect($server, $db_user, $db_pwd) //connect to the database server
or die ("Could not connect to mysql because ".mysql_error());
mysql_select_db($db_name) //select the database
or die ("Could not select to mysql because ".mysql_error());
//prevent sql injection
$username=mysql_real_escape_string($_POST["username"]);
$displayname=mysql_real_escape_string($_POST["displayname"]);
$password=mysql_real_escape_string($_POST["password"]);
$email=mysql_real_escape_string($_POST["email"]);
$bio=mysql_real_escape_string($_POST["bio"]);
//check if user exist already
$query="select * from ".$table_name." where username='$username'";
$result=mysql_query($query,$con) or die('error');
if (mysql_num_rows($result))
{
die($msg_reg_user);
}
//check if user exist already
$query="select * from ".$table_name." where email='$email'";
$result=mysql_query($query,$con) or die('error');
if (mysql_num_rows($result))
{
die($msg_reg_email);
}
session_start();
$_SESSION['displayname'] = $displayname;
$_SESSION['bio'] = $bio;
$activ_key = sha1(mt_rand(10000,2222).time().$email);
$hashed_password = crypt($password);
$query="insert into ".$table_name."(username,displayname,password,email,activ_key,bio)
values ('$username','$displayname','$hashed_password','$email','$activ_key','$bio')";
if (!mysql_query($query,$con))
{
die('Error: ' . mysql_error());
}