I am trying to insert items into a database and if the user has not entered anything in the field then i want the database to register NULL. This is'nt happening. Can anyone help please.
Here is the code i am using.
<?php
include "includes\connect.php";
include "includes\header.php";
print_r($POST);
echo "<br>";
//Information
$spot_name = $POST['spot_name'];
$address = $POST['address'];
$suburb = $POST['suburb'];
$town = $POST['town'];
$county = $POST['county'];
$country = $_POST['country'];
//Obstacles
if (isset($POST['rails']))
{
$rails = $POST['rails'];
echo "<br>$rails";
}
else {
$rails = "";
}
if (isset($POST['steps']))
{
$steps = $POST['steps'];
echo "<br>$steps";
}
else {
$steps = "";
}
if (isset($POST['ledges']))
{
$ledges = $POST['ledges'];
echo "<br>$ledges";
}
else {
$ledges = "";
}
if (isset($POST['gap']))
{
$gaps = $POST['gap'];
echo "<br>$gaps";
}
else {
$gaps = "";
}
if (isset($POST['drop']))
{
$drops = $POST['drop'];
echo "<br>$drops";
}
else {
$drops = "";
}
if (isset($POST['manual']))
{
$manuals = $POST['manual'];
echo "<br>$manuals<br>";
}
else {
$manuals = "";
}
//Images
//$image1 = $_POST[''];
$information_insert = "INSERT INTO spot_information ( name , address , suburb , town , county , country)
VALUES (
'$spot_name', '$address', '$suburb', '$town', '$county', '$country'
)";
$information_result = mysql_query($information_insert) or die (mysql_error());
$spot_id = mysql_insert_id();
echo "Spot id is $spot_id <br>";
$obstacle_insert = "INSERT INTO obstacles (spot_id , rails , steps , ledges, gaps , drops, manuals) VALUES ($spot_id, '$rails', '$steps', '$ledges', '$gaps', '$drops', '$manuals')";
$obstacle_result = mysql_query($obstacle_insert) or die (mysql_error());
?>
<html>
<head>
<title>Thanks for adding <?php echo $spot_name; ?> to the list.</title>
</head>
<body>
Thanks for adding <?php echo $spot_name; ?> to the list.
<br>
<a href='index.php'>Click here to go back to the home page</a>
</body>
</html>
<?php include "includes\footer.php"; ?>
Thanks very much