Can anyone please help. I am wanting to have a form with 3 drop down mens, one for the date, month and year. I want to enter these into a mySQL database but am unsure of how to combine these three items into one 'date' field within the database?

can someone please help!?!?

    I am working on the assumption that you store your date in timestamp (if not you should)

    $sql = "INSERT INTO
        `foor`
        ( `bar` )
    VALUES
        UNIX_TIMESTAMP( '$year-$month-$day 00:00:00' )";

    Where your values $year $month and $day come from your dropdowns

    you can also use the PHP [MAN]mktime[/MAN] function

      forgive my lack of PHP knowledge, but this is the code I had...
      where should I add this bit?
      my date, month and year are labelled as CCSTdate CCSTmonth CCSTyear.


      <?php require_once('Connections/connDukes.php'); ?>
      <?php
      function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
      {
      $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

      switch ($theType) {
      case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;

      case "long":
      case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
      case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
      case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
      case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
      }
      return $theValue;
      }

      $editFormAction = $SERVER['PHP_SELF'];
      if (isset($
      SERVER['QUERY_STRING'])) {
      $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
      }

      if ((isset($POST["MM_insert"])) && ($POST["MM_insert"] == "profile_add")) {
      $insertSQL = sprintf("INSERT INTO tbl_users (userfirstname, userlastname, userpassword, useremail, usertel, usermob, userfax, Address1, Address2, towncity, county, postcode, hospital, grade, ccstdate, ccstmonth, ccstyear, userGroup) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
      GetSQLValueString($POST['userfirstname'], "text"),
      GetSQLValueString($
      POST['userlastname'], "text"),
      GetSQLValueString($POST['userpassword'], "text"),
      GetSQLValueString($
      POST['useremail'], "text"),
      GetSQLValueString($POST['usertel'], "text"),
      GetSQLValueString($
      POST['usermob'], "text"),
      GetSQLValueString($POST['userfax'], "text"),
      GetSQLValueString($
      POST['address1'], "text"),
      GetSQLValueString($POST['address2'], "text"),
      GetSQLValueString($
      POST['towncity'], "text"),
      GetSQLValueString($POST['county'], "text"),
      GetSQLValueString($
      POST['postcode'], "text"),
      GetSQLValueString($POST['hospital'], "text"),
      GetSQLValueString($
      POST['grade'], "text"),
      GetSQLValueString($POST['ccstdate'], "int"),
      GetSQLValueString($
      POST['ccstmonth'], "int"),
      GetSQLValueString($POST['ccstyear'], "date"),
      GetSQLValueString($
      POST['Usergroup'], "text"));

      mysql_select_db($database_connDukes, $connDukes);
      $Result1 = mysql_query($insertSQL, $connDukes) or die(mysql_error());

      $insertGoTo = "mmadmin.php";
      if (isset($SERVER['QUERY_STRING'])) {
      $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
      $insertGoTo .= $
      SERVER['QUERY_STRING'];
      }
      header(sprintf("Location: %s", $insertGoTo));
      }
      ?>

        argh you use ternaries!! :eek:
        your code is quite exotic lol, I will look at it when i come back from dinner 😃.
        First time I see a sprintf used in this manner

          LoL, this is dreamweaver code!!!
          I would really appreciate your help. I am trying to get it to input the date into the mySQL database field called CCSTDATE.

          best regards
          PHiL

            I should say it currently is set to inout each element i.e. the date into a field called CCSTdate and month into a field called CCSTmonth...etc.

            hope you can help.

              ok i normally use timestamps to store dates so i was a little surprised by your structure so forget my piece of code.

              Explain what your problem is (what you want to do, and what what you have does)

                $datevalue=$CCSTyear."-".$CCSTmonth."-".$CCSTdate;

                mysql_query("insert into tbluser (date) VALUES ('$datevalue")");

                this will result date ("YYYY-mm-dd") in your table

                  Ok my problem is I have a bunch of fields that are inserting into a database, 3 of these fields are drop down menus, one for the day one for the month and one for the year. I want to combine these with the other inserts and insert them into mySQL database, however I want the date to be inserted as one column within the database.

                  The bit of code above kind of makes sense, but where do I put it within my code (also above) ????

                  please can anyone help?

                    Write a Reply...