Hi,
This is my code
<?php
// Start session
session_start();
session_name ('tmpssession');
// If not logged in then redict to index.php
if (!isset($_SESSION['agent']) OR ($_SESSION['agent'] != md5($_SERVER['HTTP_USER_AGENT'])) ) {
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
$url = substr ($url, 0, -1);
}
$url .= '/index.php';
header("Location: $url");
exit();
}
// Add the header to the page
include ('header.php');
// Connect to the database
require_once ('mysql_connect.php');
// Create the dropdown
$query = mysql_query("select id, name, ladder from maps");
$dropdown .= "<select name=dropdowntrack><option value=\"12345\">Please select a map</option>";
while($bob = mysql_fetch_array($query)){
$ladder = ucfirst(strtolower($bob[ladder]));
$dropdown.= "<option value=$bob[id]>$bob[name] - $ladder</option>";
}
$dropdown.= "</select>";
// HTML upload table
echo"
<form enctype='multipart/form-data' method='post'>
<input type='hidden' name='MAX_FILE_SIZE' value='100000' />
<p>Select a replay file you would like to create a match with, you can change it:</p>
<p><b>File:</b> <input type='file' name='upload' /> <BR>
<p><b>Track:</b> $dropdown <BR>
<div align='center'><input type='submit' name='submit' value='Submit' /></div>
<input type='hidden' name='submitted' value='TRUE' />
</fieldset>
</form>";
// Check if the form has been submitted:
if (isset($_POST['submitted'])) {
// Check for an uploaded file:
if (isset($_FILES['upload'])) {
//Check if the file is gbx image and it's size is less than 350Kb
$filename = basename($_FILES['upload']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
$ext = strtolower($ext);
if ($ext != "gbx") {
echo 'You are only allowed to upload gbx files';
include ('footer.php');
exit();
}
// Move the file over.
if (move_uploaded_file ($_FILES['upload']['tmp_name'], "replays/{$_FILES['upload']['name']}")) {
echo '<p>The replay has been uploaded. To view the offline match you created click Current Match under the Offline heading on the left menu.</p>';
} // End of move... IF.
} // End of isset($_FILES['upload']) IF.
// Check for an error:
if ($_FILES['upload']['error'] > 0) {
echo '<p>The file could not be uploaded due to an error. Please try again. </p>';
} // End of error IF.
// Delete the file if it still exists:
if (file_exists ($_FILES['upload']['tmp_name']) && is_file($_FILES['upload']['tmp_name']) ) {
unlink ($_FILES['upload']['tmp_name']);
}
$filename = "replays/{$_FILES['upload']['name']}";
include_once("gbxdatafetcher.inc.php");
$gbx = new GBXReplayFetcher($filename, true);
//print_r($gbx);
$replaytime = $_SESSION['time'];
$replayusername = $_SESSION['replayusername'];
$id = $_SESSION['id'];
// Define the dropdown
$dt = $_POST['dropdowntrack'];
// Check if the correct dropdown has been selected
if ($id != $dt){
echo 'You have selected the wrong map in the dropdown or uploaded a track not in the map pack';
include ('footer.php');
exit();
}
// Check if a replay has been uploaded
if ($replaytime == ''){
echo 'Upload a replay not track';
include ('footer.php');
exit();
}
$username = $_SESSION['username'];
$ran = rand(5,8);
$date = date("l d F Y" , strtotime("+ $ran days", strtotime(date("l d F Y"))));
// Fetch the name of the track
$query = "SELECT name FROM maps WHERE id = '$id'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
$name = $row['name'];
mysql_query("INSERT INTO race (username1, time1, time, trackid, trackname) VALUES ('$username', '$replaytime', '$date', '$id', $name)");
}
unset($_SESSION['time']);
unset($_SESSION['replayusername']);
unset($_SESSION['id']);
include ('footer.php');
?>
The problem is that for example when $id != $dt it echos "You have selected the wrong map in the dropdown or uploaded a track not in the map pack" like it should but it also echos "The replay has been uploaded. To view the offline match you created click Current Match under the Offline heading on the left menu." Not too sure why and the file doesnt even get uploaded.
Also when the file gets uploaded the form still stays there I cant seem to get it to dispear but I want it there when the errors come up.
I think ive muddled my if statments or the curly brakets or something. Anyone see anything odd
Thanks