Php- Form Not Working

Discussion in 'PHP' started by tomcool32, Jan 27, 2013.

  1. #1
    Trying to make a simple submission form.
    It's a tutorial (even then it's ****ing up! Jesus Christ!)

    OK so here's the code
    I can't find any error.
    Can you? (Not a trick question.)
    It's a clean set. AddScore.php
    When I click on submit it just clears the fields and NOTHING HAPPENS.
    Nothing gets added to the database.
    No echo of the entry
    Nothing.
    There's index.php too. Let me know if it's needed to cross check.

    <!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
    //Define the upload path and maximum file size constants
    define ('GW_UPLOADPATH', 'images/');
     
      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)) {
        //Move the file to the target upload folder
        $target= GW_UPLOADPATH . $screenshot;
        if (move_upload_files($_FILES['screenshot']['tmp_name'], $target)) {
          // Connect to the database
          $dbc = mysqli_connect('localhost', 'Thomson', 'cV5nNzRufpTCJbuz', 'gwdb')
          or die('Error accessing database');
     
          // 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 . '</p>';
          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">Please enter all of the information to add your high score.</p>';
        }
      }
    ?>
     
      <hr />
      <form enctype="mutlipart/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="screeshot" name="screenshot" />
        <hr />
        <input type="submit" value="Add" name="submit" />
      </form>
    </body>
    </html>
    Code (markup):
     
    tomcool32, Jan 27, 2013 IP
  2. Sano000

    Sano000 Active Member

    Messages:
    52
    Likes Received:
    4
    Best Answers:
    5
    Trophy Points:
    53
    #2
    Try put one more '}' on line 51 :)
     
    Sano000, Jan 27, 2013 IP
  3. tomcool32

    tomcool32 Member

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #3
    Would have gone nuts if that had worked!
    But no man. It still just clears the fields.
    No entry. No echo :(
     
    tomcool32, Jan 27, 2013 IP
  4. Sano000

    Sano000 Active Member

    Messages:
    52
    Likes Received:
    4
    Best Answers:
    5
    Trophy Points:
    53
    #4
    ok, next try
    <form enctype="mutlipart/form-data" "method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"
    <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"
    Code (markup):
     
    Sano000, Jan 27, 2013 IP
  5. tomcool32

    tomcool32 Member

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #5
    Nope
    didn't make a difference
     
    tomcool32, Jan 27, 2013 IP
  6. Sano000

    Sano000 Active Member

    Messages:
    52
    Likes Received:
    4
    Best Answers:
    5
    Trophy Points:
    53
    #6
    if (move_upload_files($_FILES['screenshot']['tmp_name'], $target)) {

    if (move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)) {
    Code (markup):
    And turn on error messages
    http://www.phoca.cz/documents/16-joomla/336-how-to-enable-displaying-php-errors-on-site
     
    Sano000, Jan 27, 2013 IP
  7. tomcool32

    tomcool32 Member

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #7
    Ok I tried too. Still no difference.
    And I am using Xampp to host it locally. Is it off by default? Because I do get Syntax errors.
     
    tomcool32, Jan 27, 2013 IP
  8. tomcool32

    tomcool32 Member

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #8
    Figured it out.
    Thanks for all the help, Sano000

    ###################################END OF THREAD#####################
     
    tomcool32, Jan 27, 2013 IP