O'Reilly Forums: Page 269 - Chapter 5 - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Page 269 - Chapter 5 "Parse error" and not sure why

#1 User is offline   NickoCP 

  • New Member
  • Pip
  • Group: Members
  • Posts: 8
  • Joined: 04-April 11

Posted 02 February 2013 - 01:17 AM

I'm on page 269 of the PHP & MySQL book and I've got a parse error for some reason, and I'm not quite sure why. Here is my addscore.php file:

<!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" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Guitar Wars - Add Your High Score</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
  <h2>Guitar Wars - Add Your High Score</h2>

<?php
  require_once(connectvars.php);
  require_once(appvars.php);

  if (isset($_POST['submit'])) {
    // Grab the score data from the POST
    $name = $_POST['name'];
    $score = $_POST['score'];
    $screenshot = $_FILES['screenshot']['name'];
 
       if (!empty($name) && !empty($score) && !empty($screenshot)) {
       if ((($screenshot_type == 'image/gif') || ($screenshot_type == 'image/jpeg') ||
       ($screenshot_type == 'image/pjpeg') || ($screenshot_type == 'image/png')) && ($screenshot_size > 0) && ($screenshot_size <= GW_MAXFILESIZE)) {
      if ($_FILES['file']['error'] == 0) {
      // Move the file to the target upload folder
      $target = GW_UPLOADPATH . $screenshot;
      if (move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)) {
      // Connect to the database
      $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
      // Write the data to the database
      $query = "INSERT INTO guitarwars VALUES (0, NOW(), '$name', '$score', '$screenshot')"; mysqli_query($dbc, $query);
      // Confirm success with the user
      echo '<p>Thanks for adding your new high score!</p>';
      echo '<p><strong>Name:</strong> ' . $name . '<br />';
      echo '<strong>Score:</strong> ' . $score . '<br />';
      echo '<img src="' . GW_UPLOADPATH . $screenshot . '" alt="Score image" /></p>'; echo '<p><a href="index.php">&lt;&lt; Back to high scores</a></p>';
      // Clear the score data to clear the form
      $name = "";
      $score = "";
      $screenshot = "";
      mysqli_close($dbc);
      }
      else {
      echo '<p class="error">Sorry, there was a problem uploading your screen shot image.</p>'; } } }
      else {
      echo '<p class="error">The screen shot must be a GIF, JPEG, or PNG image file no ' .
      'greater than ' . (GW_MAXFILESIZE / 1024) . ' KB in size.</p>'; }
      // Try to delete the temporary screen shot image file
      @unlink($_FILES['screenshot']['tmp_name']);
      }
      else {
      echo '<p class="error">Please enter all of the information to add your high score.</p>';
      }
?>

  <hr />
  <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input type="hidden" name="MAX_FILE_SIZE" value="32768" />
    <label for="name">Name:</label>
    <input type="text" id="name" name="name" value="<?php if (!empty($name)) echo $name; ?>" /><br />
    <label for="score">Score:</label>
    <input type="text" id="score" name="score" value="<?php if (!empty($score)) echo $score; ?>" /><br />
    <label for="screenshot">Screen shot:</label>
    <input type="file" id="screenshot" name="screenshot" />
    <hr />
    <input type="submit" value="Add" name="submit" />
  </form>
</body> 
</html>


If someone could have a quick look and try to figure out the problem that would be great. Thanks
0

#2 User is offline   drewdin 

  • Super Veteran Member
  • PipPipPipPipPipPipPipPipPipPipPip
  • Group: Members
  • Posts: 591
  • Joined: 11-February 10
  • Gender:Male
  • Location:Boston

Posted 03 February 2013 - 05:21 PM

You have a few errors, the first is your missing a closing bracket on your first if statement. next your require statements are incorrect. good luck!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users