Im trying to use session variables to save the puzzle key, and than open a new file that prints it out, but it gives me
Notice: Undefined index: puzzleName in C:\Apache2.2\htdocs\users\jmdrenning0\wordfind\wordfindkey2.php on line 13

i have no idea what it means, any help please.

wordfind.php

function printPuzzle(){
	//print puzzle
	
	global $puzzle, $word, $keyPuzzle, $boardData;
	//print puzzle itself
	
	print <<<HERE
	<h1>{$boardData["name"]}</h1>
	$puzzle
	<h3>Word List</h3>
	<u1>
	
HERE;
	//print word list
	foreach ($word as $theWord){
		$theWord = rtrim($theWord);
		print "<li>$theWord</li>\n";
	}
	print "</ul>\n";
	$puzzleName = $boardData["name"];
	
	//print form for requesting answer key
	//save answer key as session variable
	
	$_Session["key"] = $keyPuzzle;
	$_Session["puzzleName"] = $puzzleName;
	
	print <<<HERE
	
	<form action = "wordfindkey2.php"
		  method = "post"
		  id = "keyForm">
		  
	<div>
	<input type = "submit"
		   value = "show answer key" />
	</div>
	</form>

HERE;
}

this is wordfindkey2.php

<?php session_start() ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Word Find Answer Key</title>
<link rel="stylesheet" type="text/css" href="wordfind.css" />
</head>
<body>
<?php
// answer key for word find called from session variable

$puzzleName = $_SESSION["puzzleName"];
$key = $_SESSION["key"];


//$_Session["key"] = $keyPuzzle;
//$_Session["puzzleName"] = $puzzleName;
print <<<HERE
<h1>$puzzleName Answer key</h1>
$key
HERE;
?>
</body>
</html>

Recommended Answers

All 3 Replies

In wordfind.php, when you set the session variables, the session variables should be capitalized like this.

$_SESSION["key"] = $keyPuzzle;
$_SESSION["puzzleName"] = $puzzleName;
Member Avatar for diafol

You have named $_SESSION correctly in the second file, but have named it $_Session (incorrect) in the first. Variables are case sensitive.

wow, i feel stupid, i know i have to have it as $_SESSION but didnt realize that was the problem. I put it as $_SESSION["key"] and such. It works fine, thanks guys.

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.