missing form data

I’m creating a form for entering property details as part of a bigger project to improve my non existent php skills! When I enter data in the form and click submit I get a “missing form data, please check” error. Here’s the php.

[php]<?php

session_save_path("/tmp"); //fix godaddy issue
session_start();
include “common.php”;
$message = $_GET[‘message’];

//COLLECT POST data
$formValue=array();
foreach ($_POST as $key => $value) {
$formValue[$key] = strip_tags($value);

//Post the data back to the form keeping the data the user has already typed
$_SESSION[‘post_vars’][$key] = $value;
}//close for loop

if(isset($_POST[‘Submit’])){

//Check for empty fields
if($formValue[‘Address1’]=="" || $formValue[‘Address2’]=="" || $formValue[‘Address3’]=="" || $formValue[‘PostCode’]=="" || $formValue[‘Bedrooms’]=="" || $formValue[‘Price’]=="" || $formValue[‘Description’]=="" || $formValue[‘PriceBand’]==""){

$message = “missing form data, please check” ;
header(“Location: addNewProperty.php?message=$message”);

}else{
//Carry on with routine if there is no missing data

DBConnect();
$Link = mysql_connect($Host, $User, $Password);

//$agentID = $_SESSION[‘userID’];
$agentID = “1”;

$Query = “INSERT INTO $Table_2 VALUES (‘0’, '”.mysql_escape_string($formValue[‘PostCode’])."’,’".mysql_escape_string($formValue[“Price”])."’, ‘".mysql_escape_string($formValue[“PriceBand”])."’,’".mysql_escape_string($formValue[“Bedrooms”])."’, ‘".mysql_escape_string($formValue[“Address1”])."’, ‘".mysql_escape_string($formValue[“Address2”])."’, ‘".mysql_escape_string($formValue[“Address3”])."’, ‘".mysql_escape_string($formValue[“Description”])."’, '";

if(mysql_db_query ($DBName, $Query, $Link)){
$message = “Property Inserted Successfully!”;
header(“Location: addNewProperty.php?message=$message”);
}else{
$message = “Error Inserting!”;
header(“Location: addNewProperty.php?message=$message”);
}//close db query conditional
}//close form validation conditional
}//close form submit conditional

?>
[/php]

And the HTML :

[code]

Add New Property
Address 1
Address 2
Town/City
Postcode
Bedrooms
Price
Price Band
Description
<?php print $message ; ?> [/code]

In your addNewProperty.php your $_POST variable names are not correct.

In your form, most of them are lowercase. You need to do:[php]//Check for empty fields
if($formValue[‘address1’]=="" || $formValue[‘address2’]=="" || $formValue[‘address3’]=="" || $formValue[‘postCode’]=="" || $formValue[‘bedrooms’]=="" || $formValue[‘price’]=="" || $formValue[‘Description’]=="" || $formValue[‘priceband’]==""){[/php]

Let me know if this fixes the problem. If not, I will look at the code further.

I’ve changed to field names to match those in the database. I now get ‘Error Inserting!’ error.

[php]<?php

session_save_path("/tmp"); //fix godaddy issue
session_start();
include “common.php”;
$message = $_GET[‘message’];

//COLLECT POST data
$formValue=array();
foreach ($_POST as $key => $value) {
$formValue[$key] = strip_tags($value);

//Post the data back to the form keeping the data the user has already typed
$_SESSION[‘post_vars’][$key] = $value;
}//close for loop

if(isset($_POST[‘Submit’])){

//Check for empty fields
if($formValue[‘Address1’]=="" || $formValue[‘Address2’]=="" || $formValue[‘Address3’]=="" || $formValue[‘PostCode’]=="" || $formValue[‘Bedrooms’]=="" || $formValue[‘Price’]=="" || $formValue[‘Description’]=="" || $formValue[‘PriceBand’]==""){

$message = “missing form data, please check” ;
header(“Location: addNewProperty.php?message=$message”);

}else{
//Carry on with routine if there is no missing data

DBConnect();
$Link = mysql_connect($Host, $User, $Password);

//$agentID = $_SESSION[‘userID’];
//$agentID = “1”;

$Query = “INSERT INTO $Table_2 VALUES (‘0’, '”.mysql_escape_string($formValue[‘PostCode’])."’,’".mysql_escape_string($formValue[“Price”])."’, ‘".mysql_escape_string($formValue[“PriceBand”])."’,’".mysql_escape_string($formValue[“Bedrooms”])."’, ‘".mysql_escape_string($formValue[“Address1”])."’, ‘".mysql_escape_string($formValue[“Address2”])."’, ‘".mysql_escape_string($formValue[“Address3”])."’, ‘".mysql_escape_string($formValue[“Description”])."’, '";

if(mysql_db_query ($DBName, $Query, $Link)){
$message = “Property Inserted Successfully!”;
header(“Location: addNewProperty.php?message=$message”);
}else{
$message = “Error Inserting!”;
header(“Location: addNewProperty.php?message=$message”);
}//close db query conditional
}//close form validation conditional
}//close form submit conditional

?>[/php]

[code]

Add New Property
Address 1
Address 2
Town/City
PostCode
Bedrooms
Price
Price Band
Description
<?php print $message ; ?> [/code]

Still not working. Any ideas?

Sponsor our Newsletter | Privacy Policy | Terms of Service