thecase Posted June 18, 2009 Share Posted June 18, 2009 Hi, This is my code <?php error_reporting(E_ALL); // 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'); $errorfileext = 'true'; unlink($_FILES['upload']['tmp_name']); exit(); } $string = "{$_FILES['upload']['name']}"; $string1 = preg_replace('/[^0-9a-z.]+/i', '', $string); // Move the file over. if (move_uploaded_file($_FILES['upload']['tmp_name'], "replays/$string1")) { } // Check if there is allready a file with the same name $result = mysql_query('SELECT download1 FROM race WHERE download1 = "replays/$string1" '); $num_rows = mysql_num_rows($result); if ($num_rows > 0) { echo 'Please rename the file'; include('footer.php'); exit(); } } // 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/$string1"; include_once("gbxdatafetcher.inc.php"); $gbx = new GBXReplayFetcher($filename, true); // print_r($gbx); $replaytime = $_SESSION['time']; $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'; $errordropdown = 'true'; include('footer.php'); exit(); } // Check if a replay has been uploaded if ($replaytime == '') { echo 'Upload a replay not track'; $errortrack = 'true'; include('footer.php'); exit(); } if ($errorfileext || $errordropdown || $errortrack != 'true') { 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>'; } $username = $_SESSION['username']; $ran = rand(5, ; $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', 'dowload1') VALUES ('$username', '$replaytime', '$date', '$id', $name, $filename)"); } unset($_SESSION['time']); unset($_SESSION['id']); include('footer.php'); ?> Some reason towards the end of the script is the db insert that is not being inserted can anyone see anything odd? If you can also see anything that can be improved in the script please show me im new to this Thanks Quote Link to comment Share on other sites More sharing options...
Maq Posted June 18, 2009 Share Posted June 18, 2009 You need single quotes around $name, and $filename. If that doesn't work try adding this or die clause at the end: mysql_query("INSERT INTO race ('username1', 'time1', 'time', 'trackid', 'trackname', 'dowload1') VALUES ('$username', '$replaytime', '$date', '$id', $name, $filename)") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
thecase Posted June 18, 2009 Author Share Posted June 18, 2009 I just get You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''username1', 'time1', 'time', 'trackid', 'trackname', 'dowload1') VALUES ('Test'' at line 1 as an error. Cant see anything wrong though. Quote Link to comment Share on other sites More sharing options...
Maq Posted June 18, 2009 Share Posted June 18, 2009 You don't need single quotes around the field names: (username1, time1, time, trackid, trackname, dowload1) Quote Link to comment Share on other sites More sharing options...
thecase Posted June 19, 2009 Author Share Posted June 19, 2009 Thanks that worked Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.