LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-26-2008, 03:15 AM   #1
linux1943
LQ Newbie
 
Registered: Nov 2008
Location: Newbiggin by the Sea
Distribution: openSuse and Centos
Posts: 1

Rep: Reputation: 0
Question Form input "birthday" to mysql


I have a mysql database set up and one field is to hold a date of birth. I have set this to DATE. How do I set up a FORM field to enter the d.o.b. which will be acepted in the data base field (using php)
eg INSERT INTO name,birthday etc.
Regards
 
Old 11-26-2008, 09:51 AM   #2
nehaandrew
Member
 
Registered: Nov 2008
Posts: 53

Rep: Reputation: 15
I believe this is "just what the doctor ordered" - http://www.weberdev.com/get_example-3287.html

Enjoy!


Linux

Last edited by nehaandrew; 11-30-2008 at 01:16 AM.
 
Old 11-26-2008, 09:57 AM   #3
MicahCarrick
Member
 
Registered: Jul 2004
Distribution: Fedora
Posts: 241

Rep: Reputation: 31
There are many options. You can have 3 boxes for date/month/year, you could have a date picking widget using Javascript, you could require a specific format for entry with validation, etc. What I like to do, is use PHP's strtotime() function. You will still want to give the user a hint as to the format (ie mm/dd/YYYY is not the same as dd/mm/YYYY but your code won't know that!). So this method isn't 100% full proof, but, it gets the job done in many situations and is very simple.

Code:
function sql_date_format($value) 
{
    if (gettype($value) == 'string') $value = strtotime($value);
    return date('Y-m-d H:i:s', $value);
}

$birthday = $_POST['birthday'];

// Note: Clean up and validate "birthday" variable here

$birthday = sql_date_format($birthday);
$birthday = mysql_real_escape_string($birthday);

$sql = "INSERT INTO some_table (birthday) VALUES ('$birthday')";
mysql_query($sql) or die('Insert failed for birthday = '.$birthday);
 
Old 11-26-2008, 09:58 AM   #4
MicahCarrick
Member
 
Registered: Jul 2004
Distribution: Fedora
Posts: 241

Rep: Reputation: 31
Sorry, that example was for the MySQL DATETIME data type. For the DATE format, change 'Y-m-d H:i:s' to 'Y-m-d'.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash variable problem: cURL -b parameter (string form e.g. "name=value;n2=v2") sithemac Other *NIX 3 07-09-2008 06:15 PM
Repeated "input: AT Translated Set 2 keyboard as /class/input/input" messages AcerKev Mandriva 2 09-16-2007 08:35 AM
kdevelop error "Cannot find implementation class for form" J3N7iL Linux - Software 0 06-28-2006 12:11 AM
form action ="?" ... where is my form posting to? verbatim Programming 2 05-23-2005 06:55 PM
<input type="button" disabled="true" > does not work in ns4.7 or 4.9 cybercop12us Programming 2 11-29-2002 08:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration