Hi there. I seem to be having a problem with an if statement within the following PHP code. I have a form which a user can fill in, in order to add house details to a database such as price, description and image etc. This PHP script throws up no errors when it is run and is working perfectly fine. However, the if statement I have used to display an error message if the user doesn't fill in all the fields isn't working. When I submit a blank form the data isn't inserted into the database which it is designed to do, but the error message isn’t displayed. The only reason I can think of is because I have an input type file within the form and maybe this is causing the PHP to misread it. Any feedback would be much appreciated.
Code:
<?php
include('connect.php');
$target = "./houses";
$target = $target . basename($_FILES['photo']['name']);
if (isset($_POST['submit']))
{
$price = mysql_real_escape_string(htmlspecialchars($_POST['price']));
$rooms = mysql_real_escape_string(htmlspecialchars($_POST['rooms']));
$address = mysql_real_escape_string(htmlspecialchars($_POST['address']));
$description = mysql_real_escape_string(htmlspecialchars($_POST['description']));
$photo = (mysql_real_escape_string($_FILES['photo']['name']));
if ($price == '' || $rooms == '' || $address == '' || $description == '')
{
$error = 'ERROR TRYING TO ADD A NEW RECORD: Please fill in all required fields';
form($price, $rooms, $address, $description, $photo, $error);
}
else
{
mysql_query("INSERT house_info SET price='$price', rooms='$rooms', address='$address', description='$description', photo='$photo'")
or die(mysql_error());
header("Location:admin.php");
}
}
else
{
form('','','','','','');
}
?>
Comment