calvinschools Posted May 5, 2011 Share Posted May 5, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/235566-this-is-simple-i-know-but-i-cant-find-it/ Share on other sites More sharing options...
fugix Posted May 5, 2011 Share Posted May 5, 2011 well there are no syntax error in the code...i assume that your if statement criteria is not being met Quote Link to comment https://forums.phpfreaks.com/topic/235566-this-is-simple-i-know-but-i-cant-find-it/#findComment-1210707 Share on other sites More sharing options...
calvinschools Posted May 5, 2011 Author Share Posted May 5, 2011 how can that be? I filled in all fields met all criteria. I'm at a lost. Quote Link to comment https://forums.phpfreaks.com/topic/235566-this-is-simple-i-know-but-i-cant-find-it/#findComment-1210712 Share on other sites More sharing options...
btherl Posted May 5, 2011 Share Posted May 5, 2011 This looks sus to me: $photo = $_FILES['photo']['partner_name']; Quote Link to comment https://forums.phpfreaks.com/topic/235566-this-is-simple-i-know-but-i-cant-find-it/#findComment-1210713 Share on other sites More sharing options...
fugix Posted May 5, 2011 Share Posted May 5, 2011 ah yes $photo = $_FILES['photo']['partner_name']; is not valid Quote Link to comment https://forums.phpfreaks.com/topic/235566-this-is-simple-i-know-but-i-cant-find-it/#findComment-1210714 Share on other sites More sharing options...
fugix Posted May 5, 2011 Share Posted May 5, 2011 you need to have either $photo = $_FILES['photo']['name']; or $photo = $_FILES['photo']['tmp_name']; Quote Link to comment https://forums.phpfreaks.com/topic/235566-this-is-simple-i-know-but-i-cant-find-it/#findComment-1210716 Share on other sites More sharing options...
fugix Posted May 5, 2011 Share Posted May 5, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/235566-this-is-simple-i-know-but-i-cant-find-it/#findComment-1210717 Share on other sites More sharing options...
calvinschools Posted May 5, 2011 Author Share Posted May 5, 2011 thanks guys. One more thing and my website is finished. But I'll save it for tomorrow. I need some sleep. Quote Link to comment https://forums.phpfreaks.com/topic/235566-this-is-simple-i-know-but-i-cant-find-it/#findComment-1210730 Share on other sites More sharing options...
fugix Posted May 5, 2011 Share Posted May 5, 2011 glad we could help Quote Link to comment https://forums.phpfreaks.com/topic/235566-this-is-simple-i-know-but-i-cant-find-it/#findComment-1210737 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.