Jump to content

This is simple I know but I can't find it


Recommended Posts

Anybody know why I'm getting "Please fill in all fields" error? I put comments in to make it easier


<!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>Who's Missing?</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
  <h2>Someone Missing?</h2>

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

  if (isset($_POST['submit'])) {
    // Grab the score data from the POST
    $name = $_POST['name'];
    $partner_name = $_POST['partner_name'];
$state = $_POST['state'];
    $photo = $_FILES['photo']['partner_name'];
    $photo_type = $_FILES['photo']['type'];
    $photo_size = $_FILES['photo']['size']; 

    if (!empty($name) && !empty($partner_name)
&& !empty($state) && !empty($photo)) {

if ((($photo_type == 'image/gif') || ($photo_type == 'image/jpeg') || ($photo_type == 'image/pjpeg') || ($photo_type == 'image/png'))
        && ($photo_size > 0) && ($photo_size <= GW_MAXFILESIZE)) {
        if ($_FILES['photo']['error'] == 0) {
// Move the file to temp
  $target = GW_UPLOADPATH . $photo;
  if (move_uploaded_file($_FILES['photo']['tmp_name'], $target)) {
// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

// Write to the database
$query = "INSERT INTO guitarwars VALUES (0, NOW(), '$name', '$partner_name', '$state', '$photo')";
mysqli_query($dbc, $query);

// Confirm success with the user
echo '<p>Partner added. Enjoy!</p>';
echo '<p><strong>Name:</strong> ' . $name . '<br />';
echo '<strong>Partner:</strong> ' . $partner_name . '<br />';
echo '<strong>State:</strong> ' . $state . '<br />';
echo '<img src="' . GW_UPLOADPATH . $photo . '" alt="Score image" /></p>';
echo '<p><a href="guitar.php"><< Back to Partners page</a></p>';

// Clear the data to clear the form
            $name = "";
            $partner_name = "";
		$state = "";
            $photo = "";

            mysqli_close($dbc);
          }
          else {
echo '<p class="error">Sorry, there was a problem uploading your partners photo.</p>';
          }
        }
      }
else {
	echo '<p class="error">The photo must be a GIF, JPEG, or PNG image file no greater than ' . (GW_MAXFILESIZE / 320768) . ' MB in size.</p>';
      }
// delete the temporary photo image file
@unlink($_FILES['photo']['tmp_name']);
    }
    else {
      echo '<p class="error">Please fill in all fields.</p>';
    }
  }
?>

  <hr />
<form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo GW_MAXFILESIZE; ?>" />
<label for="name">Name:</label>
<input type="text" id="name" name="name" value="<?php if (!empty($name)) echo $name; ?>" /><br />
<label for="partner">Partner:</label>
<input type="text" id="partner_name" name="partner_name" value="<?php if (!empty($partner_name)) echo $partner_name; ?>" /><br />
<label for="state">State:</label>
<input type="text" id="state" name="state" value="<?php if (!empty($state)) echo $state; ?>" /><br />
<label for="photo">Photo:</label>
<input type="file" id="photo" name="photo" />
    <hr />
<input type="submit" value="Add Partner" name="submit" />
  </form>
</body> 
</html>

Link to comment
Share on other sites

im assuming that it fails when this

if (!empty($name) && !empty($partner_name)
&& !empty($state) && !empty($photo))

is ran...since $photo was equal to an invalid $_FILES array value..it always returned empty

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.