Sending user input date of birth to mysql database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
geoffmuskett
Forum Newbie
Posts: 22
Joined: Sat Feb 27, 2010 3:09 pm

Sending user input date of birth to mysql database

Post by geoffmuskett »

Hi, I'm trying to collect a users date of birth when they register but am struggling to send it to the database in the correct format (or any format!). This is what I have:

Code: Select all

$dob_eploded = explode("/", $dob);	
	$dob_timestamp = mktime(0,0,0,$dob_eploded[0], $dob_eploded[1], $dob_eploded[2]);
$dob is the value they sent in the format dd/mm/yyyy. The database stores them in the this format: 0000-00-00 00:00:00.

When the mysql query with $dob_timestamp is sent there's no error, the database just isn't updating.

Thanks,

Geoff
wurdup
Forum Commoner
Posts: 39
Joined: Thu Apr 01, 2010 11:36 am

Re: Sending user input date of birth to mysql database

Post by wurdup »

geoffmuskett wrote:Hi, I'm trying to collect a users date of birth when they register but am struggling to send it to the database in the correct format (or any format!). This is what I have:

Code: Select all

$dob_eploded = explode("/", $dob);	
	$dob_timestamp = mktime(0,0,0,$dob_eploded[0], $dob_eploded[1], $dob_eploded[2]);
$dob is the value they sent in the format dd/mm/yyyy. The database stores them in the this format: 0000-00-00 00:00:00.

When the mysql query with $dob_timestamp is sent there's no error, the database just isn't updating.

Thanks,

Geoff
are you putting the $dob_timestamp in the correct way? atm you have it in the wrong sequence. If the format is wrong the data will just show as 0000-00-00 00:00:00 in the db. you need to put y-m-d time in mysql
geoffmuskett
Forum Newbie
Posts: 22
Joined: Sat Feb 27, 2010 3:09 pm

Re: Sending user input date of birth to mysql database

Post by geoffmuskett »

Cheers wurdup!

This works (may not be the best solution, but hey):

Code: Select all

$dob_eploded = explode("/", $child_dob);	
$date_formatted = $dob_eploded[2] . "-" . $dob_eploded[1] . "-" . $dob_eploded[0] . " 00:00:00";
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Sending user input date of birth to mysql database

Post by AbraCadaver »

Why not use date time functions?

Code: Select all

$dob = date('Y-m-d', strtotime($dob));
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply