Jump to content

foreach $_POST find blank fields


unistake

Recommended Posts

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");
}
}	
?>

Link to comment
Share on other sites

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)));

Link to comment
Share on other sites

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");
}
}

Link to comment
Share on other sites

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!";
}
?>

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.