Page 1 of 1

cant insert into mysql date (yyyy-mm-dd) field

Posted: Sat Nov 15, 2003 1:29 am
by justravis
i hav 2 selectboxes for month & yr.

Code: Select all

<?php
 $grad_date= "$grad_yr-$grad_mo-00";

 $studquery="INSERT INTO student (`first`, `last`, `nick`, `ss`, `pass`, `phone`, `email`, `emph_id`, `units_left`, `grad_date`) values ('$first', '$last', '$nick', '$ss', '$pass', '$phone', '$email', '$emphasis', '$units_left', '$grad_date')";

?>
All the other fields insert except the grad_date just ends up 0000-00-00.

ANY IDEAS WOULD BE GREATLY APPRECIATED!!!!

Posted: Sat Nov 15, 2003 1:39 am
by Paddy
$grad_date must be in the form yyyy-mm-dd

I reckon if you echoed $grad_date you would get

$grad_yr-$grad_mo-00

right? That is because you haven't concatenated the string properly.

Code: Select all

<?php
$grad_date= $grad_yr."-".$grad_mo."-00";
?>
would be the proper way to do it. As long as grad_yr is four digits and $grad_mo is two you should have no problems.

Posted: Sat Nov 15, 2003 1:50 am
by justravis
i tried that b4....i just tried again by cutiing & pasting yr code...same result.

Code: Select all

<?php
$grad_date= $grad_yr."-".$grad_mo."-00";
?>
thank you for yr time

Posted: Sat Nov 15, 2003 1:59 am
by Paddy
Have you echoed $grad_date to see what it is?

Posted: Sat Nov 15, 2003 2:09 am
by justravis
echoes '2003--00'

guess month is not coming through....dont know y...dbl checked feild names ages ago

Posted: Sat Nov 15, 2003 5:01 am
by Paddy
Well post code for that and we'll try to fix. :)

Posted: Sat Nov 15, 2003 1:37 pm
by twigletmac
Where do $grad_yr and $grad_mo come from?

Mac