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

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
justravis
Forum Commoner
Posts: 53
Joined: Mon Dec 16, 2002 3:18 am
Location: San Diego, CA
Contact:

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

Post 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!!!!
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post 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.
justravis
Forum Commoner
Posts: 53
Joined: Mon Dec 16, 2002 3:18 am
Location: San Diego, CA
Contact:

Post 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
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

Have you echoed $grad_date to see what it is?
justravis
Forum Commoner
Posts: 53
Joined: Mon Dec 16, 2002 3:18 am
Location: San Diego, CA
Contact:

Post by justravis »

echoes '2003--00'

guess month is not coming through....dont know y...dbl checked feild names ages ago
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

Well post code for that and we'll try to fix. :)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Where do $grad_yr and $grad_mo come from?

Mac
Post Reply