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