Jump to content

Information isn't posting to my xml page (leader board)


lanceox

Recommended Posts

hi guys, the problem is, is that all of the code works fine, however im trying to post the user to the leader board (leaders.xml) however it just isnt adding to the xml page and im not too sure why.

 

I  attached all 3 files that you may need to see to figure it out.  Hope you can really help, I would really appreciate it.

 

Okay this section is the index where the user enters their user name

<?php
session_name("elearning_Test");
session_start();
$_SESSION['score'] = 0;
$_SESSION['correct'] = array(); 
$_SESSION['wrong'] = array();
$_SESSION['finished'] = 'no'; 
$_SESSION['num'] = 0;
require_once ('functions.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Forensics E-learning Package</title>
    <script type="text/javascript" src="start.js"></script>

<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="wrapper">
<div id="header">
<div id="toplinks">

</div>
</div>
<div id="menu">
	<ul>
		<li><a class="selected" href="home.html">Home</a></li>
		<li><a href="initialquiz.php">Initial Quiz</a></li>
		<li><a href="about.php">About</a></li>
            <li><a href="leaderboard.php">Leader Board</a></li>

	</ul>
  </div>
<div id="content">
	<div id="main">
		<h1>Forensics E-Learning Package</h1><BR />
          <h2>Start The Test</h2>
          <form id="questionBox" method="post" action="home.php">
<label for="username">Create A Username:</label><br />
<input type="text" id="username" name="username" value="Username" />
<p id="exp">Username must be between 3 and 10 characters in length</p></li>
</ul>
<p><input type="hidden" name="register" value="TRUE" />
<input type="submit" id="submit" value="Register And Take The Test" /></p>
</form> 

<p id="helper"><?php if(isset($_SESSION['error'])) echo $_SESSION['error']; ?></p>

	</div>
	<div id="right">
	<h2>Right Menu</h2>
	<div class="rightitem">
		<ul>
		<li><a class="selected" href="home.html">Home</a></li>
		<li><a href="initialquiz.php">Initial Quiz</a></li>
		<li><a href="about.php">About</a></li>
            <li><a href="leaderboard.php">Leader Board</a></li>
		</ul>
	</div>
	</div>
  </div>
<div class="clearbottom"></div>
<div id="footer">
	<p id="legal"> </p>
</div>
</div>
</div>
</body>
</html>

 

This section is the leaderboardpage

<?php
session_name("elearning_Test");
session_start();

include_once('functions.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Forensics E-learning Package</title>

<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="wrapper">
<div id="header">
<div id="toplinks">

</div>
</div>
<div id="menu">
	<ul>
		<li><a class="selected" href="index.php">Home</a></li>
		<li><a href="index.php">Initial Quiz</a></li>
		<li><a href="index.php">About</a></li>

	</ul>
  </div>
<div id="content">
	<div id="main">
        <h1>Leader Board</h1>
        <h2>Top Scorers</h2>
        

<?php
echo "Welcome to the Leaderboard " . $_SESSION['user']; ?><BR /><BR />
<?php
showLeaders('leaders.xml',20); ?><BR /><BR />


    
        
        </div>
	<div id="right">
	<h2>Right Menu</h2>
	<div class="rightitem">
		<ul>
		<li><a class="selected" href="index.php">Home</a></li>
		<li><a href="index.php">Initial Quiz</a></li>
		<li><a href="index.php">About</a></li>
		</ul>
	</div>
	</div>
  </div>
<div class="clearbottom"></div>
<div id="footer">
	<p id="legal"> </p>
</div>
</div>
</div>
</body>
</html>

 

And finally this section is the functions page.

 


<?php

// shuffle answers
function shuffle_assoc($array) {

  $keys = array_keys($array);
  shuffle($keys);
  $shuffled = array();
  foreach ($keys as $key)
    $shuffled[$key] = $array[$key];

  return $shuffled;
} 
  
  
// leader board section
function showLeaders($file,$limit,$group = null) { 
$leaders = array();

// Load the xml file and place all users and associated 
	// scores into the 'leaders' array.
	$xml = simplexml_load_file($file);
	foreach($xml->user as $user) 
{
		$name = (string)$user->name;
		$score = (string)$user->score;
		$leaders[$name] = $score;
	}

	// Sort the leaders array numerically, highest scorers first.	
	arsort($leaders,SORT_NUMERIC);

	// Initialise our $counter variable to '1'.
	$counter = 1;

	// Start a html ordered list to hold the leaders.
	$output = "<ul class=\"leaders\">\n";

	// Loop through the 'leaders' array and wrap each username and score
	// in <li> tags. If the user is the current $_SESSION['user'], wrap
	// the name/score in <strong> tags too.
	foreach ($leaders as $key => $value) 
{
		// Check that $counter is less than $limit.
		if ($counter <= $limit)
	{
			if ($key == $_SESSION['user'])
		{
				$output .= "<li><strong>$key:</strong> $value/20</li>\n";
			}
		else 
		{
				$output .= "<li>$key: $value/20</li>\n";
			}
			// Check to see if $group parameter has been passed.
			// If it has, create separate lists according to the $group variable.
			if ($group) 
		{
				// Use the modulus operator(%) to create new sub-list.
				if($counter % $group == 0) 
			{
					$output .= "</ul>\n<ul class=\"leaders\">\n";
				}
			}
		}
	// Increment the $counter.	
	$counter++;
	}
	// End the ordered list.
	$output .= "</ul>\n";

	// Print out the ordered list.
echo $output;
}

function showAnswers($answers,$questions) { 
for($x = 0; $x< count($answers); $x++) {
	if ($x % 2 == 0) { 
	 	$output = "<div class=\"qanda clear\">\n";
	} else { 
		$output = "<div class=\"qanda\">";
  		}
	$output .= '<h4>Question' . ($x+1) . ': ' . $questions[$x] . '</h4>'; 
$output .= "<ol>\n";
	for ($y = 0;$y< count($answers[$x]); $y++) {
		if (($answers[$x][$y] === $answers[$x][0]) && (in_array($answers[$x][$y],$_SESSION['correct']))) {
			$output .= "<li class=\"correctuser\">{$answers[$x][$y]} (Correct!)</li>\n";
		} else if ($answers[$x][$y] === $answers[$x][0]) {
			$output .= "<li class=\"correct\">{$answers[$x][$y]}</li>\n";
		} else if (in_array($answers[$x][$y],$_SESSION['wrong'])) {
			$output .= "<li class=\"wrong\">{$answers[$x][$y]} (Woops!)</li>\n";
		} else { 
			$output .= "<li>{$answers[$x][$y]}</li>\n";
	}
}
$output .= "</ol></div>\n";
echo $output;
}
}
?>	

 

Thanks guys for your help.  Just really need another pair of eyes on this as i cant see why.

 

Lance

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.