austin6118 Posted May 1, 2009 Share Posted May 1, 2009 I'm trying to set the year month and day to the server on mysql in one field but am having trouble doing so. Here is my code so far <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php // process form include("connectDB.php"); $date = $_POST['year'].$_POST['month'].$_POST["day"]; $sql = "INSERT INTO reminder(eventName, eventNote, date, hour, min, amPM) VALUES ('{$_REQUEST['eventName']}','{$_REQUEST['eventNote']}','{$_REQUEST['date']}','{$_REQUEST['hour']}','{$_REQUEST['min']}','{$_REQUEST['amPM']}')"; $result = mysql_query($sql) or die("Sorry, please enter your correct informaiton \n");; echo "Thank You! Your information has been submitted"; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/156447-php-concatination-with-year-month-day-and-mysql/ Share on other sites More sharing options...
gnawz Posted May 1, 2009 Share Posted May 1, 2009 I still don't get you.. What do you mean set the date, month and year in one field? Quote Link to comment https://forums.phpfreaks.com/topic/156447-php-concatination-with-year-month-day-and-mysql/#findComment-823760 Share on other sites More sharing options...
austin6118 Posted May 1, 2009 Author Share Posted May 1, 2009 What I am trying to set up is an event reminder. The user will be able to set a year month and day for a email reminder about the event. I am trying to upload the year month and day using type DATE on the MYSQL server. I have three drop down menus to set the year month and day. I want it so that when they submit the form it gets submitted as one field on the database in the type DATE format which is yyyy/mm/dd. Quote Link to comment https://forums.phpfreaks.com/topic/156447-php-concatination-with-year-month-day-and-mysql/#findComment-823769 Share on other sites More sharing options...
gnawz Posted May 1, 2009 Share Posted May 1, 2009 I see. Why don't you use PHP/MySQL date functions as opposed to drop downs? You can also use date pickers to make it easier. Google date pickers, you will find some. Otherwise Do something like: $year = $_POST['year']; $month = $_POST['month']; $day = $_POST['day']; Then a new variable for concatenation $reminderdate = $year.$month.$day; $reminderdate is what you save in the DB Quote Link to comment https://forums.phpfreaks.com/topic/156447-php-concatination-with-year-month-day-and-mysql/#findComment-823786 Share on other sites More sharing options...
Ken2k7 Posted May 1, 2009 Share Posted May 1, 2009 You probably want to use a delimiter in that concatenated date string or else you won't be able to pick it apart. Quote Link to comment https://forums.phpfreaks.com/topic/156447-php-concatination-with-year-month-day-and-mysql/#findComment-823788 Share on other sites More sharing options...
the182guy Posted May 1, 2009 Share Posted May 1, 2009 The default date format for MySQL is YYYY-MM-DD so you will need to use the hyphen to seperate the three values. Quote Link to comment https://forums.phpfreaks.com/topic/156447-php-concatination-with-year-month-day-and-mysql/#findComment-823828 Share on other sites More sharing options...
nankoweap Posted May 2, 2009 Share Posted May 2, 2009 i do the same thing in some pages... it's as simple as: $reminderDate = $_REQUEST['year'] . '-' . $_REQUEST['month'] . '-' . $_REQUEST['day']; and then using that value in your SQL. be sure to set the values of the month and day dropdowns to zero-padded values. for instance, january is 01, february is 02, etc. Quote Link to comment https://forums.phpfreaks.com/topic/156447-php-concatination-with-year-month-day-and-mysql/#findComment-823912 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.