I don't what is wrong but there's an error
Error: Incorrect date value: '' for column 'DateBirth' at row 1

I searched for answers but there seems nothing wrong with my code. I used date as datatype for date of birth.

my php script.

<?php
$m = $_POST["month"];
$d = $_POST["day"];
$y = $_POST["year"];
$datebirth = $y . $m . $d;

mysql_query("INSERT INTO StoreTbl (DateofBirth) values('$datebirth')", $con);
?>

Day and Year uses for loop

<?php
echo "<select name='day'>";

for ($i=0; $i<=30; $i++)
{
$day = 1 + $i;

echo "<option value = $day>" . $day ."</option>";
}
echo "</select>";


echo "<select name='year'>";

for($i=0; $i<=59; $i++)
{
$year = 2005 - $i;

echo "<option value = $year>" . $year . "</option>";
}
echo "</select>";

So what's wrong?

I believe there's nothing wrong with my for loop too.

When I view the source code it's fine

<option value='31'>31</option>

Replace your line 5

$datebirth = $y . $m . $d;

with this

$datebirth = $y."-".$m."-".$d;
commented: thanks +3

I tried that but

Error: Incorrect date value: '--' for column 'DateBirth' at row 1

I found out the problem. I'm running the PHP script everytime I load the page. So, I set the isset() function. I don't know exactly the fix but I do get it. Thanks. :p

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.