Hello everybody,
I've posted this question before but i got no help, may be i wasn't clear enough or it can't be solved but i really need someones help.
The problem is my if else statement. My if else conditions will block the first two int values but then allow the rest of the form data into the DB even if flagged as empty.
<?php
session_start();
require("config.php");
require("functions.php");
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);
$propertytype = $_POST['propertytype'];
$age = $_POST['age'];
$grade = $_POST['grade'];
$style = $_POST['style'];
$nofl = $_POST['nofl'];
$adres = $_POST['adres'];
$startingprice = $_POST['startingprice'];
if(isset($_SESSION['USERNAME']) == FALSE) {
header("Location: " . $config_basedir . "/login.php?ref=newitem");
}
if($_POST['submitted']) {
$validdate = checkdate($_POST['month'], $_POST['day'], $_POST['year']);
if($validdate == TRUE) {
$concatdate = $_POST['year']
. "-" . sprintf("%02d", $_POST['month'])
. "-" . sprintf("%02d", $_POST['day'])
. " " . $_POST['hour']
. ":" . $_POST['minute']
. ":00";
$itemsql = "INSERT INTO items(user_id,propertytype,age,grade,style,nofl,adres,startingprice,dateends) VALUES(". $_SESSION['USERID']. ",'" . addslashes($_POST['propertytype']). "', " . $_POST['age'] . ", '" . addslashes($_POST['grade']) . "', '" .addslashes( $_POST['style']) . "', " . $_POST['nofl'] . ",'" . addslashes($_POST['adres']) . "', " . $_POST['startingprice'] . ", '" . $concatdate . "');";
mysql_query($itemsql);
$itemid = mysql_insert_id();
header("Location: " . $config_basedir . "/addimages.php?id=" . $itemid);
}
else
{
header("Location: " . $config_basedir . "/newitem.php?error=date");
}
if (empty($_POST['age']) )
{
header("Location: " . $config_basedir . "/newitem.php?error=age");
}
if (empty($_POST['grade']) )
{
header("Location: " . $config_basedir . "/newitem.php?error=grade");
}
if (empty($_POST['style']) )
{
header("Location: " . $config_basedir . "/newitem.php?error=style");
}
if (empty($_POST['nofl']) )
{
header("Location: " . $config_basedir . "/newitem.php?error=nofl");
}
if (empty($_POST['adres']) )
{
header("Location: " . $config_basedir . '"/newitem.php?error=adres"');
}
}
else {
require("header.php");
?>
<table width="447"class="abc">
<strong>Step 1- Add details. </strong>
</table>
<?php
switch($_GET['error']) {
case "date":
echo "<strong>Invalid date - please choose another!</strong>";
break;
case "age":
echo "<strong>Invalid age - please enter the age of the property!</strong>";
break;
case "grade":
echo "<strong>Invalid grade - please enter the grade of the property!</strong>";
break;
case "style":
echo "<strong>Invalid style - please enter the style of the property!</strong>";
break;
case "nofl":
echo "<strong>Invalid nofl - please enter the nofl of the property!</strong>";
break;
case "adres":
echo "<strong>Invalid adres - please enter the adres of the property!</strong>";
break;
}
?>