Jump to content

PHP concatination with year month day and MYSQL


austin6118

Recommended Posts

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>

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.

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

 

 

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.