unistake Posted October 19, 2010 Share Posted October 19, 2010 Hi all, I am trying to write a script that finds the blank $_POST values and add them to a $blank_array. All I get is a blank page - any ideas? Also is there some code I can put at the top of every php page to show exactly what the errors are? - I have tried a few scripts but have not found one to work universally. include("cxn.php"); $reg = "G-".strtoupper($_POST['reg']); $sql = "SELECT * FROM sales WHERE reg='$reg'"; $result = mysqli_query($cxn,$sql) or die ("Couldn't execute query"); $num = mysqli_num_rows($result); if ($num >0) // Listing Already Found { echo "The aircraft '$reg' is already listed!"; echo $_SESSION['logname']; } foreach ($_POST as $value) { if ($value == "") { $blank_array[] = $field; } if (@sizeof($blank_array) > 0) // blank fields are found { $error = "Please fill in all the form.<br>"; include ("../sell-your-reg.php"); } } ?> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 19, 2010 Share Posted October 19, 2010 What about checkboxes? They don't even show up in the $_POST array unless they're actually checked . . . Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 19, 2010 Share Posted October 19, 2010 are you missing an opening tag? might explain the blank page. <?php Quote Link to comment Share on other sites More sharing options...
unistake Posted October 19, 2010 Author Share Posted October 19, 2010 the $_POST's are only text fields, drop down menu items and one radio button. They all have values. Thanks for the point on checkboxes though. Sorry I have included the <?php - left it out of the script by mistake. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted October 19, 2010 Share Posted October 19, 2010 If you have a blank page then you need this: error_reporting(E_ALL); ini_set('display_errors', '1'); As for an array of the blank fields, this will do it (caveat, 0 and one or more spaces are considered blank as well): $blank = array_diff(array_keys($_POST), array_keys(array_filter($_POST))); Quote Link to comment Share on other sites More sharing options...
unistake Posted October 19, 2010 Author Share Posted October 19, 2010 That code for seeing the errors, I placed it at the top of the page but does not show any errors - just a blank page. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 19, 2010 Share Posted October 19, 2010 are you POST-ing to the script? if not, you'll get a blank page. in fact, i don't see anything outputting anything unless there is an error. Quote Link to comment Share on other sites More sharing options...
unistake Posted October 19, 2010 Author Share Posted October 19, 2010 Yes it does, if I take out the whole 'foreach' statement the script runs through but when I try to put the blank fields in to an array it isn't. PHP is mind boggling at the best of times! Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 19, 2010 Share Posted October 19, 2010 this may need to be changed, as i don't see field defined anywhere. also, never use @. $blank_array = array(); foreach ($_POST as $field=>$value) { if ($value == "") { $blank_array[] = $field; } if (sizeof($blank_array) > 0) { $error = "Please fill in all the form.<br>"; include ("../sell-your-reg.php"); } } Quote Link to comment Share on other sites More sharing options...
unistake Posted October 20, 2010 Author Share Posted October 20, 2010 No still not working. My full code is here: Maybe it is something elsewhere in the page. <?PHP session_start(); include("../cxn.php"); $reg = "G-".strtoupper($_POST['reg']); $sql = "SELECT * FROM sales WHERE reg='$reg'"; $result = mysqli_query($cxn,$sql) or die ("Couldn't execute query"); $num = mysqli_num_rows($result); if ($num >0) // Listing Already Found { echo "The aircraft '$reg' is already listed!"; echo $_SESSION['logname']; } $blank_array = array(); foreach ($_POST as $field=>$value) { if ($value == "") { $blank_array[] = $field; } if (sizeof($blank_array) > 0) { $error = "Please fill in all the form.<br>"; include ("../sell-your-reg.php"); exit(); exit; } } else // Aircraft Listing Not Found { $password = md5($_POST['password']); $reg = "G-".strtoupper($_POST['reg']); $title = strtoupper($_POST['title']); // CHANGES THE TITLE OF THE ADVERT TO UPPER CASE $today = date("Y-m-d h:i:s"); $email = $_SESSION['logname']; $icao = strtoupper($_POST['icao']); // CHANGES ICAO CODE TO UPPER CASE $query = "INSERT INTO sales VALUES ('','$email','$title','$reg','$_POST[category]','$_POST[manufacturer]','$_POST[model]','$_POST[engines]','$_POST[seats]','$_POST[aeros]','$_POST[purchasetype]','$_POST[price]','$icao','$_POST[details]','$today')"; $result1 = mysqli_query($cxn,$query) or die ("Can't execute insert query"); $destination='../aircraft/'.$reg."1.jpg"; $temp_file = $_FILES['image']['tmp_name']; move_uploaded_file($temp_file,$destination); $destination2='../aircraft/'.$reg."2.jpg"; $temp_file2 = $_FILES['image2']['tmp_name']; move_uploaded_file($temp_file2,$destination2); $destination3='../aircraft/'.$reg."3.jpg"; $temp_file3 = $_FILES['image3']['tmp_name']; move_uploaded_file($temp_file3,$destination3); echo "your aircraft has been successfully added!"; } ?> 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.