This is a magic 8 ball program I'm doing for school, and I've been looking at the code for days, but neither I, nor my teacher can spot any errors, so if you see any, please let me know, and as I am just learning about this, if you could make the answer as simple as possible, that would help! The problem is that I'm trying to pass the information from the log in page to the main page, but neither the name, nor the answers are showing up. I checked to ensure the marquee where the name + the answer is supposed to show up was working and it is, so it has to be a problem passing the data. Here's the code:
log in:
<?php
if (isset($_COOKIE['name'])) {
header("Location:magic8ball.php");
}
?>
<!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>Magic 8 Ball</title>
<style type="text/css">
<!--
body {
background-color: #FFFFFF;
}
-->
</style></head>
<body>
<h1 align="center">Magic 8 Ball</h1>
<form name="frmLogon" action="magic8ball.php" method="get">
<p align="center"> Please tell the 8 ball your first name: <br/>
<input type="text" name="txtName" /> </p>
<p align="center"><input name="btnSubmit" type="submit" id="btnSubmit" value="Talk to the 8 Ball" />
***
<input name="btnReset" type="reset" id="Submit" value="Reset" />
</p>
<p>*</p>
</form>
</body>
</html>
main:
<?php
session_start();
if (isset($_COOKIE['name'])) {
$user = $_COOKIE['name'];
}elseif (isset($_GET['txtName'])) {
$user = $_GET['txtName'];
$expire = time() + 120;
setcookie("name", $user, $expire);
}else{
header("Location:magic8ball_login.php");
}
$randomPick = "";
$displayPick = "";
if (isset($_GET['txtQuestion'])) {
$question = $_GET['txtQuestion'];
if ($question == "" || $question == " ") {
$marquee = "Welcome to the 8 ball";
}elseif ($number == $_SESSION['priorInput']) {
$marquee = "Enter another question";
}else{
srand((double) microtime() * 10000000);
$randomPick = rand(1, 10);
$displayPick = "The lucky number is: " . $randomPick;
if ($randomPick == $number) {
$marquee = $user . ", you win!";
}else{
$marquee = $user . ", you lose!";
}
}
}else{
$marquee = "Welcome to the 8 ball, " . $user . "! What do you want to know?";
}
$_SESSION['priorInput'] = $number;
?>
<!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>Untitled Document</title>
</head>
<body>
<h1 align="center">Welcome to the Pick Number Game!</h1>
<h3 align="center">Pick a number from 1 to 10.</h3>
<form id="frmMain" name="frmMain" method="get" action="lottery-demo-OSH.php">
<p align="center">*</p>
<p align="center">
<label>
<input type="text" name="txtNumber" id="txtNumber" />
</label>
</p>
<p align="center">*<?=$number?></p>
<p align="center">*<?=$displayPick?></p>
<p>*</p>
<p align="center">
<label>
<input type="submit" name="btnPick" id="btnPick" value="Pick Number" />
</label></p>
<p align="center">*</p>
<p align="center">*</p>
<marquee><?=$marquee?></marquee>
</form>
</body>
</html>
log in:
<?php
if (isset($_COOKIE['name'])) {
header("Location:magic8ball.php");
}
?>
<!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>Magic 8 Ball</title>
<style type="text/css">
<!--
body {
background-color: #FFFFFF;
}
-->
</style></head>
<body>
<h1 align="center">Magic 8 Ball</h1>
<form name="frmLogon" action="magic8ball.php" method="get">
<p align="center"> Please tell the 8 ball your first name: <br/>
<input type="text" name="txtName" /> </p>
<p align="center"><input name="btnSubmit" type="submit" id="btnSubmit" value="Talk to the 8 Ball" />
***
<input name="btnReset" type="reset" id="Submit" value="Reset" />
</p>
<p>*</p>
</form>
</body>
</html>
main:
<?php
session_start();
if (isset($_COOKIE['name'])) {
$user = $_COOKIE['name'];
}elseif (isset($_GET['txtName'])) {
$user = $_GET['txtName'];
$expire = time() + 120;
setcookie("name", $user, $expire);
}else{
header("Location:magic8ball_login.php");
}
$randomPick = "";
$displayPick = "";
if (isset($_GET['txtQuestion'])) {
$question = $_GET['txtQuestion'];
if ($question == "" || $question == " ") {
$marquee = "Welcome to the 8 ball";
}elseif ($number == $_SESSION['priorInput']) {
$marquee = "Enter another question";
}else{
srand((double) microtime() * 10000000);
$randomPick = rand(1, 10);
$displayPick = "The lucky number is: " . $randomPick;
if ($randomPick == $number) {
$marquee = $user . ", you win!";
}else{
$marquee = $user . ", you lose!";
}
}
}else{
$marquee = "Welcome to the 8 ball, " . $user . "! What do you want to know?";
}
$_SESSION['priorInput'] = $number;
?>
<!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>Untitled Document</title>
</head>
<body>
<h1 align="center">Welcome to the Pick Number Game!</h1>
<h3 align="center">Pick a number from 1 to 10.</h3>
<form id="frmMain" name="frmMain" method="get" action="lottery-demo-OSH.php">
<p align="center">*</p>
<p align="center">
<label>
<input type="text" name="txtNumber" id="txtNumber" />
</label>
</p>
<p align="center">*<?=$number?></p>
<p align="center">*<?=$displayPick?></p>
<p>*</p>
<p align="center">
<label>
<input type="submit" name="btnPick" id="btnPick" value="Pick Number" />
</label></p>
<p align="center">*</p>
<p align="center">*</p>
<marquee><?=$marquee?></marquee>
</form>
</body>
</html>