Jump to content

[SOLVED] Session Variables


twilitegxa

Recommended Posts

I have a form that is going to span over several pages, so I have to store the inputs into session variables. I have gotten most of the post data to carry over and insert into the table in the database, but I can't figure out how to get the username to pull in because it is not defined from this page that is pulling the other session variables. The way I have it set up currently is, to view the "creationform.php" page, you must be signed in, so if you click the page, it redirects you to the "login.php" page.

 

1) Firstly, I notice that I have my redirect set to go to the account.php page when the user signs in. I need to know how to redirect the user to the previous page they were at or attempting to access when they were redirected to the login page. I can't set a specific page because sometimes people will log in and need to be directed to whatever page they were accessing before they were directed to log in. How can I do this?

 

2) Secondly, after they log in and are redirected, how do I save the username from where they signed in as a session variable in order to insert this into the table upon submission of the form at the very end and final page?

 

3) I currently am testing the session variables so I only have it going from the creationform.php to scouts.php, to stats.php, and then the final page is insert.php. The sessions I have saved so far are only being pulled from scouts.php.

 

login.php

<?php

//Access Tracking Snippet

//set up static variables
$page_title = "login.php";
$user_agent = getenv("HTTP_USER_AGENT");
$date_accessed = date("Y-m-d");

//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
or die(mysql_error());
$db = mysql_select_db("smrpg", $conn) or die(mysql_error());

//create and issue query
$sql = "insert into access_tracker values
('', '$page_title', '$user_agent', '$date_accessed')";
mysql_query($sql,$conn);
?>

<?php
session_start();

$user_area_location = 'account.php'; // Location of the user area
// Connect to MySQL database:
$access = mysql_connect('localhost','root','') or die ('Could not connect to database');
mysql_select_db('smrpg',$access) or die ('Could not select table');
# #
$error = array();
if(isset($_GET['action'])) {
switch($_GET['action']) {
case 'logoff':
unset($_SESSION['loggedIn']);
array_push($error, 'You were logged off.');
break;
}
}
if(!$error) {
if(empty($_POST['username'])) { array_push($error, 'You didn\'t supply a username'); }
if(empty($_POST['password'])) { array_push($error, 'You didn\'t supply a password'); }
}
if(!$error){
$result = @mysql_query('SELECT username, email, name FROM `users` WHERE username = \''.mysql_real_escape_string($_POST['username']).'\' AND password = \''.mysql_real_escape_string(md5($_POST['password'])).'\'');
if($row = @mysql_fetch_array($result)) {
$_SESSION['loggedIn'] = true;
$_SESSION['userName'] = $row['username']; 
$_SESSION['userMail'] = $row['email'];
$_SESSION['name'] = $row['name'];
header('Location: '.$user_area_location);
die('<a href="'.$user_area_location.'">Go to your user account</a>');
}else{
array_push($error, 'The username or password you provided were not correct');
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Sailor Moon RPG - Login</title>
<!-- Source File -->
<style type="text/css" media="screen">
/*<![CDATA[*/
@import url(global.css); 
/*]]>*/
</style>
</head>
<body>
<!-- HEADER -->
<h1 class="logo">Sailor Moon RPG</h1>
<!-- /HEADER -->
<?php include("topnav.php"); ?>
<div id="main">
<?php include("includes/log.php"); ?>
<?php include("mainnav.php"); ?>
<table cellspacing="2" cellpadding="0" border="0">
<form method="post" action="login.php">
<?php if(isset($error) && $error) { ?>
<tr>
<td colspan="2">
<ul><?php foreach($error as $key => $value) echo '<li>'.$value.'</li>'; ?></ul>
</td>
</tr><?php } ?>
<tr>
<td>Username:</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Login!" /> <a href="forgot.php">I forgot my username or password</a></td>

</tr>
</form>
</table>
</div>
<?php include("bottomnav.php"); ?>
<!-- FOOTER -->
<div id="footer_wrapper">
<div id="footer">
<p>Sailor Moon and all characters are<br>
trademarks of Naoko Takeuchi.</p>
<p>Copyright © 2009 Liz Kula. All rights reserved.<br>
A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p>
<div id="foot-nav"><!-- <ul>
<li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li>
<li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li>
</ul> --></div>
</div>
</div>
<!-- /FOOTER -->
</body>
</html>

 

creationfor,.php

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<?php

session_start();

if(!isset($_SESSION['loggedIn'])) {
header("Location: login.php");
}

//Access Tracking Snippet

//set up static variables
$page_title = "creationform.php";
$user_agent = getenv("HTTP_USER_AGENT");
$date_accessed = date("Y-m-d");

//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
        or die(mysql_error());
$db = mysql_select_db("smrpg", $conn) or die(mysql_error());

//create and issue query
$sql = "insert into access_tracker values
        ('', '$page_title', '$user_agent', '$date_accessed')";
mysql_query($sql,$conn);

$gender = (!empty($_POST['gender']))?$_POST['gender']:""; //Male or female?
$status = (!empty($_POST['status']))?$_POST['status']:""; //Hero or villain?

if($status == "villain"){
if($gender == "male") {
	//You are a male villain
	header("Location: mdark_warrior.php");
	exit;
	}elseif($gender == "female"){
	//You are a female villain
	header("Location: fdark_warrior.php");
	exit;
	}
}elseif($status == "hero"){
        if($gender == "male"){
                //You are a male hero!
                header("Location: knight.php");
        exit;
        }elseif($gender == "female"){
                //You are a female hero!
                header("Location: scout.php");
        exit;
        }
}
?>
<head>
<title>Sailor Moon RPG - Character Creation - Step 2: Character Outline</title>

<style type="text/css" media="screen">
/*<![CDATA[*/
@import url(global.css); 
/*]]>*/
</style>
</head>
<body>
<!-- HEADER -->
<h1 class="logo">Sailor Moon RPG</h1>
<!-- /HEADER -->
<?php include("topnav.php"); ?>
<div id="main">
<?php include("includes/log.php"); ?>
<?php include("mainnav.php"); ?>
<h1>Step 2: Character Outline - Creation</h1>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table>
<tr>
<td>Would you like to create a:</td>
<td><input type="radio" name="status" value="hero"> Hero or a <input type="radio" name="status" value="villain" class="input1"> Villain</td>
</tr>
<tr>
<td></td>
<td><input type="radio" name="gender" value="female"> Female or <input type="radio" name="gender" value="male"> Male</td>
</tr>
</table>
<br>
<input type="submit" name="submit" value="Create Character" class="button1"> <input type="reset" name="reset" value="Reset"></form>
</div>
<?php include("bottomnav.php"); ?>
<!-- FOOTER -->
<div id="footer_wrapper">
<div id="footer">
<p>Sailor Moon and all characters are<br>
trademarks of Naoko Takeuchi.</p>
<p>Copyright © 2009 Liz Kula. All rights reserved.<br>
A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p>
<div id="foot-nav"><!-- <ul>
<li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li>
<li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li>
</ul> --></div>
</div>
</div>
<!-- /FOOTER -->
</body>
</html>

 

scout.php

<?php

session_start();

//Access Tracking Snippet

//set up static variables
$page_title = "scout.php";
$user_agent = getenv("HTTP_USER_AGENT");
$date_accessed = date("Y-m-d");

//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
or die(mysql_error());
$db = mysql_select_db("smrpg", $conn) or die(mysql_error());

//create and issue query
$sql = "insert into access_tracker values
('', '$page_title', '$user_agent', '$date_accessed')";
mysql_query($sql,$conn);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sailor Moon RPG - Character Creation Form | Scout</title>
<style type="text/css" media="screen">
/*<![CDATA[*/
@import url(global.css); 
/*]]>*/
</style>
</head>
<body>
<!-- HEADER -->
<h1 class="logo">Sailor Moon RPG</h1>
<!-- /HEADER -->
<?php include("topnav.php"); ?>
<div id="main">
<?php include("includes/log.php"); ?>
<?php include("mainnav.php"); ?>
<form action="stats.php" method="post">
<h1>Step 2: Character Outline - Creation</h1>
<h2><u>Scout Profile</u></h2>
<table border="0">
  <tr>
    <td>Identity:</td>
    <td><input type="text" name="identity" size="30" maxlength="100"></td>
  </tr>

  <tr>
    <td>Character Name:</td>
    <td><input type="text" name="name" size="30" maxlength="100"></td>
  </tr>

  <tr>
    <td>Element Of Influence:</td>
    <td>

    <SELECT NAME="element_of_influence" SIZE="1">
    <OPTION value="Purity And The Soul">Purity/Soul</OPTION>
    <OPTION value="Water">Water</OPTION>
    <OPTION value="Fire">Fire</OPTION>
    <OPTION value="Wood/Lightning">Wood/Lightning</OPTION>
    <OPTION value="Love/Metal">Love/Metal</OPTION>

    <OPTION value="Earth">Earth</OPTION>
    <OPTION value="Time">Time</OPTION>
    <OPTION value="Death And Healing">Death/Healing</OPTION>
    <OPTION value="Light">Light</OPTION>
    </SELECT> <a href="elements.php" title="Help!"><img src="question.gif" /></a></td>
  </tr>

<tr>
    <td>Age:</td>
    <td><input type="text" name="age" size="2" maxlength="2"></td>
  </tr>
    <tr>
    <td>Date Of Birth:</td>
    <td><SELECT NAME="birth_month" SIZE="1">
    <OPTION value="01">January</OPTION>
    <OPTION value="02">February</OPTION>
    <OPTION value="03">March</OPTION>
    <OPTION value="04">April</OPTION>
    <OPTION value="05">May</OPTION>
    <OPTION value="06">June</OPTION>
    <OPTION value="07">July</OPTION>
    <OPTION value="08">August</OPTION>
    <OPTION value="09">September</OPTION>
    <OPTION value="10">October</OPTION>
    <OPTION value="11">November</OPTION>
    <OPTION value="12">December</OPTION>
    </SELECT>

    <SELECT NAME="birth_date" SIZE="1">
    <OPTION value="01">1</OPTION>
    <OPTION value="02">2</OPTION>
    <OPTION value="03">3</OPTION>
    <OPTION value="04">4</OPTION>
    <OPTION value="05">5</OPTION>
    <OPTION value="06">6</OPTION>
    <OPTION value="07">7</OPTION>
    <OPTION value="08">8</OPTION>
    <OPTION value="09">9</OPTION>
    <OPTION value="10">10</OPTION>
    <OPTION value="11">11</OPTION>
    <OPTION value="12">12</OPTION>
    <OPTION value="13">13</OPTION>
    <OPTION value="14">14</OPTION>
    <OPTION value="15">15</OPTION>
    <OPTION value="16">16</OPTION>
    <OPTION value="17">17</OPTION>
    <OPTION value="18">18</OPTION>
    <OPTION value="19">19</OPTION>
    <OPTION value="20">20</OPTION>
    <OPTION value="21">21</OPTION>
    <OPTION value="22">22</OPTION>
    <OPTION value="23">23</OPTION>
    <OPTION value="24">24</OPTION>
    <OPTION value="25">25</OPTION>
    <OPTION value="26">26</OPTION>
    <OPTION value="27">27</OPTION>
    <OPTION value="28">28</OPTION>
    <OPTION value="29">29</OPTION>
    <OPTION value="30">30</OPTION>
    <OPTION value="31">31</OPTION>
    </SELECT> </td>
  </tr>
  <tr>
    <td>Height:</td>
    <td><input type="text" name="height_feet" size="2" maxlength="2"> feet <input type="text" name="height_inches" size="2" maxlength="2"> inches</td>

  </tr>
  <tr>
    <td>Blood Type:</td>
    <td><input type="text" name="blood_type" size="4" maxlength="4"> <a href="bloodtype.php" title="Help!"><img src="question.gif" /></a>    </td>
  </tr>
  <tr>
    <td>Hobbies:</td>

    <td><input type="text" name="hobbies" size="30" maxlength="100">
    </td>
  </tr>
  <tr>
    <td>Favorite Color:</td>
    <td><input type="text" name="favorite_color" size="10" maxlength="30">
    </td>
  </tr>

  <tr>
    <td>Favorite Gemstone:</td>
    <td><input type="text" name="favorite_gemstone" size="10" maxlength="10">
    </td>
  </tr>
  <tr>
    <td>Favorite Food:</td>
    <td><input type="text" name="favorite_food" size="10" maxlength="30">

    </td>
  </tr>
  <tr>
    <td>Least Favorite Food:</td>
    <td><input type="text" name="least_favorite_food" size="10" maxlength="30">
    </td>
  </tr>
  <tr>

    <td>Favorite School Subject:</td>
    <td><input type="text" name="favorite_school_subject" size="10" maxlength="10">
    </td>
  </tr>
  <tr>
    <td>Least Favorite School Subject:</td>
    <td><input type="text" name="least_favorite_school_subject" size="10" maxlength="10">
    </td>

  </tr>
  <tr>
    <td>Strengths:</td>
    <td><input type="text" name="strengths" size="30" maxlength="100">
    </td>
  </tr>
  <tr>
    <td>Weaknesses:</td>

    <td><input type="text" name="weaknesses" size="30" maxlength="100">
    </td>
  </tr>
  <tr>
    <td>Goal:</td>
    <td><input type="text" name="goal" size="30" maxlength="100">
    </td>
  </tr>
<tr>
    <td>Mission:</td>
    <td><input type="text" name="mission" size="30" maxlength="100">
    </td>
  </tr>
  <tr>
    <td>Character Biography:</td>
    <td><textarea name="biography" rows=7 
cols=46></textarea>
    </td>
  </tr>
</table>
<p style="text-align: center" class="submit"><input type="submit" value="Create Character" />
<input type="reset" value="Reset" /></p>

</form>

</div>
<?php include("bottomnav.php"); ?><!-- FOOTER -->
<!-- FOOTER -->
<div id="footer_wrapper">
<div id="footer">
<p>Sailor Moon and all characters
are<br /> 
trademarks of Naoko Takeuchi.</p>
<p>Copyright © 2009 Liz Kula. All rights reserved.<br />
A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p>
<div id="foot-nav">
<ul>
<li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li>
<li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li>
</ul>
</div>
</div>
</div>
<!-- /FOOTER -->
</body>
</html>

 

stats.php

<?php

session_start();

//register our session variables
session_register('id');
session_register('create_time');
//session_register('username');
session_register('identity');
session_register('name');
session_register('element_of_influence');
session_register('age');
session_register('birth_month');
session_register('birth_date');
//session_register ('birth_year');
session_register('blood_type');
session_register('hobbies');
session_register('favorite_color');
session_register('favorite_gemstone');
session_register('favorite_food');
session_register('least_favorite_food');
session_register('favorite_school_subject');
session_register('least_favorite_school_subject');
session_register('strengths');
session_register('weaknesses');
session_register('goal');
session_register('mission');
session_register('biography');
session_register('height_feet');
session_register('height_inches');

//store our posted values in the session variables
$_SESSION['id'] = '';
$_SESSION['create_time'] = 'now()';
//$_SESSION['username'] = $_POST['username'];
$_SESSION['identity'] = $_POST['identity'];
$_SESSION['name'] = $_POST['name'];
$_SESSION['element_of_influence'] = $_POST['element_of_influence'];
$_SESSION['age'] = $_POST['age'];
$_SESSION['birth_month'] = $_POST['birth_month'];
$_SESSION['birth_date'] = $_POST['birth_date'];
//$_SESSION['birth_year'] = $_POST['birth_year'];
$_SESSION['blood_type'] = $_POST['blood_type'];
$_SESSION['hobbies'] = $_POST['hobbies'];
$_SESSION['favorite_color'] = $_POST['favorite_color'];
$_SESSION['favorite_gemstone'] = $_POST['favorite_gemstone'];
$_SESSION['favorite_food'] = $_POST['favorite_food'];
$_SESSION['least_favorite_food'] = $_POST['least_favorite_food'];
$_SESSION['favorite_school_subject'] = $_POST['favorite_school_subject'];
$_SESSION['least_favorite_school_subject'] = $_POST['least_favorite_school_subject'];
$_SESSION['strengths'] = $_POST['strengths'];
$_SESSION['weaknesses'] = $_POST['weaknesses'];
$_SESSION['goal'] = $_POST['goal'];
$_SESSION['mission'] = $_POST['mission'];
$_SESSION['biography'] = $_POST['biography'];
$_SESSION['height_feet'] = $_POST['height_feet'];
$_SESSION['height_inches'] = $_POST['height_inches'];

//Access Tracking Snippet

//set up static variables
$page_title = "stats.php";
$user_agent = getenv("HTTP_USER_AGENT");
$date_accessed = date("Y-m-d");

//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
or die(mysql_error());
$db = mysql_select_db("smrpg", $conn) or die(mysql_error());

//create and issue query
$sql = "insert into access_tracker values
('', '$page_title', '$user_agent', '$date_accessed')";
mysql_query($sql,$conn);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sailor Moon RPG - Character Creation Form | Scout</title>
<style type="text/css" media="screen">
/*<![CDATA[*/
@import url(global.css); 
/*]]>*/
</style>
<!-- to get derived values -->
<script type="text/javascript">
function handle(a,b,c) {
			var e = document.getElementsByTagName('input');
			for (i in e) {
				if (e[i].name == a) a = e[i];
				if (e[i].name == b) b = e[i];
				if (e[i].name == c) c = e[i];
			}
			c.value = (Number(a.value) + Number(b.value)) * 5;
		}

</script>

</head>
<body>
<!-- HEADER -->
<h1 class="logo">Sailor Moon RPG</h1>
<!-- /HEADER -->
<?php include("topnav.php"); ?>
<div id="main">
<?php include("includes/log.php"); ?>
<?php include("mainnav.php"); ?>
<h1>Step 2: Character Outline - Creation</h1>
<h2>Stats And Derived Values</h2>
<form action="insert.php" method="post">
<table border="0">
  <tr>
    <td>Body:</td>
    <td><input type="text" onKeyUp="handle('body','soul','health')" name="body" size="10" maxlength="2"></td>
  </tr>

  <tr>
    <td>Mind:</td>
    <td><input type="text" onKeyUp="handle('mind','soul','energy')" name="mind" size="10" maxlength="2"></td>
  </tr>
  <tr>
    <td>Soul:</td>
    <td><input type="text" onKeyUp="handle('body','soul','health')" name="soul" size="10" maxlength="2"></td>
  </tr>

<tr>
    <td></td>
    <td> </td>
  </tr>
  <tr>
    <td>Health Points:</td>
    <td><input type="text" onKeyUp="handle('body','soul')"
name="health" size="10" maxlength="3" /></td>
  </tr>
  <tr>
    <td>Energy Points:</td>
    <td><input type="text" onKeyUp="handle('mind','soul')" name="energy" size="10" maxlength="3"></td>
  </tr>
  <tr>
    <td>Attack Combat Value:</td>

    <td><input type="text" name="acv1" size="10" maxlength="3">    </td>
  </tr>
  <tr>
    <td>(Special Attack)</td>
    <td><input type="text" name="acv2" size="10" maxlength="3">    </td>
  </tr>

  <tr>
    <td>Defense Combat Value:</td>
    <td><input type="text" name="dcv1" size="10" maxlength="30">    </td>
  </tr>
  <tr>
    <td>(Special Defense)</td>
    <td><input type="text" name="dcv2" size="10" maxlength="3">    </td>
  </tr>
  <tr>
    <td>Total Character Points:</td>
    <td><input type="text" name="total_cp" size="10" maxlength="3">    </td>
  </tr>
</table>
<p style="text-align: center" class="submit"><input type="submit" value="Create Character" />
<input type="reset" value="Reset" /></p>

</form>
</div>
<?php include("bottomnav.php"); ?>
<!-- FOOTER -->
<div id="footer_wrapper">
<div id="footer">
<p>Sailor Moon and all characters are<br>
trademarks of Naoko Takeuchi.</p>
<p>Copyright © 2009 Liz Kula. All rights reserved.<br>
A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p>
<div id="foot-nav"><!-- <ul>
<li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li>
<li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li>
</ul> --></div>
</div>
</div>
<!-- /FOOTER -->
</body>
</html>

 

insert.php

<?php

session_start();

?>

<?php

//Access Tracking Snippet

//set up static variables
$page_title = "insert.php";
$user_agent = getenv("HTTP_USER_AGENT");
$date_accessed = date("Y-m-d");

//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
or die(mysql_error());
$db = mysql_select_db("smrpg", $conn) or die(mysql_error());

//create and issue query
$sql = "insert into access_tracker values
('', '$page_title', '$user_agent', '$date_accessed')";
mysql_query($sql,$conn);
?>

<?php

$identity = $_SESSION['identity'];

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("smrpg", $con);$sql="INSERT INTO scouts (id, create_time,  identity, name, element_of_influence, age, birth_month, birth_date, birth_year, height_feet, height_inches, blood_type, hobbies, favorite_color, favorite_gemstone, favorite_food, least_favorite_food, favorite_school_subject, least_favorite_school_subject, strengths, weaknesses, goal, mission, biography)
VALUES
('', now(), '$_SESSION[identity]','$_SESSION[name]','$_SESSION[element_of_influence]','$_SESSION[age]','$_SESSION[birth_month]','$_SESSION[birth_date]','$_SESSION[birth_year]','$_SESSION[height_feet]','$_SESSION[height_inches]','$_SESSION[blood_type]','$_SESSION[hobbies]','$_SESSION[favorite_color]','$_SESSION[favorite_gemstone]','$_SESSION[favorite_food]','$_SESSION[least_favorite_food]','$_SESSION[favorite_school_subject]','$_SESSION[least_favorite_school_subject]','$_SESSION[strengths]','$_SESSION[weaknesses]','$_SESSION[goal]','$_SESSION[mission]','$_SESSION[biography]')";if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
$display_block = "Your character has been successfully created! Redirecting to Your Account Page...";mysql_close($con)
?>

<html>
<head>
<title>Sailor Moon RPG - Character <?php echo $identity; ?> Created Successfully</title>
<meta HTTP-EQUIV="REFRESH" content="2; url=http://localhost/account.php">
<style type="text/css" media="screen">
/*<![CDATA[*/
@import url(global.css); 
/*]]>*/
</style>
</head>
<body>
<!-- HEADER -->
<h1 class="logo">Sailor Moon RPG</h1>
<!-- /HEADER -->
<?php include("topnav.php"); ?>
<div id="main">
<?php include("includes/log.php"); ?>
<?php include("mainnav.php"); ?>
<h1>Character <?php echo $identity; ?> Created Successfully</h1>
<?php echo $display_block; ?>

</div>
<?php include("bottomnav.php"); ?><!-- FOOTER -->
<!-- FOOTER -->
<div id="footer_wrapper">
<div id="footer">
<p>Sailor Moon and all characters
are<br /> 
trademarks of Naoko Takeuchi.</p>
<p>Copyright © 2009 Liz Kula. All rights reserved.<br />
A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p>
<div id="foot-nav">
<ul>
<li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li>
<li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li>
</ul>
</div>
</div>
</div>
<!-- /FOOTER -->
</body>
</html>

Link to comment
Share on other sites

$page = "blabla.php";
$_SESSION['bla'] = $page;

if(!isset($_SESSION['loggedIn'])) {
header("Location: login.php");
}

//then somewhere else on another page couldn'tyou just

codezzzz
header("Location: $_SESSION['bla']");

 

I don't know if this would be possible because you'd have to be constantly updating that particular session.

Link to comment
Share on other sites

The session start() is at the top of the login.php page. User name is referenced in this section of the login.php page:

 

<?php
session_start();

$user_area_location = 'account.php'; // Location of the user area
// Connect to MySQL database:
$access = mysql_connect('localhost','root','') or die ('Could not connect to database');
mysql_select_db('smrpg',$access) or die ('Could not select table');
# #
$error = array();
if(isset($_GET['action'])) {
switch($_GET['action']) {
case 'logoff':
unset($_SESSION['loggedIn']);
array_push($error, 'You were logged off.');
break;
}
}
if(!$error) {
if(empty($_POST['username'])) { array_push($error, 'You didn\'t supply a username'); }
if(empty($_POST['password'])) { array_push($error, 'You didn\'t supply a password'); }
}
if(!$error){
$result = @mysql_query('SELECT username, email, name FROM `users` WHERE username = \''.mysql_real_escape_string($_POST['username']).'\' AND password = \''.mysql_real_escape_string(md5($_POST['password'])).'\'');
if($row = @mysql_fetch_array($result)) {
$_SESSION['loggedIn'] = true;
$_SESSION['userName'] = $row['username']; 
$_SESSION['userMail'] = $row['email'];
$_SESSION['name'] = $row['name'];
header('Location: '.$user_area_location);
die('<a href="'.$user_area_location.'">Go to your user account</a>');
}else{
array_push($error, 'The username or password you provided were not correct');
}
}
?>

 

Since it is already referenced as:

 

$_SESSION['userName'] = $row['username'];

 

How do I set the session variable on the next page? i have been setting my variables like this:

 

//register our session variables

session_register('identity');

 

//store our posted values in the session variables

$_SESSION['identity'] = $_POST['identity'];

 

So how do I set this one? Since it already seems to be set as a session variable?[/code]

Link to comment
Share on other sites

Nevermind, I figured it out. I just added it to the insert statement and it worked! Thanks for the help anyway!

 

"INSERT INTO scouts (id, create_time, username, identity, name, element_of_influence, age, birth_month, birth_date, birth_year, height_feet, height_inches, blood_type, hobbies, favorite_color, favorite_gemstone, favorite_food, least_favorite_food, favorite_school_subject, least_favorite_school_subject, strengths, weaknesses, goal, mission, biography)
VALUES
('', now(), '$_SESSION[userName]',  '$_SESSION[identity]','$_SESSION[name]','$_SESSION[element_of_influence]','$_SESSION[age]','$_SESSION[birth_month]','$_SESSION[birth_date]','$_SESSION[birth_year]','$_SESSION[height_feet]','$_SESSION[height_inches]','$_SESSION[blood_type]','$_SESSION[hobbies]','$_SESSION[favorite_color]','$_SESSION[favorite_gemstone]','$_SESSION[favorite_food]','$_SESSION[least_favorite_food]','$_SESSION[favorite_school_subject]','$_SESSION[least_favorite_school_subject]','$_SESSION[strengths]','$_SESSION[weaknesses]','$_SESSION[goal]','$_SESSION[mission]','$_SESSION[biography]')";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.