Jump to content

[SOLVED] Using a variable to insert a date


Evollusion

Recommended Posts

Hello everyone, I've got a little bit of an issue here and the fact that I'm a PHP neophyte is an understatement.  Anyway, I've got this snippet of code that does perform 90% of the action that I want it to perform, but it does not add the value provided by the $fulldate variable into the table.  When I check my php admin website the date shows up as all zeros instead of the proper date provided in the variable.

 

When I run this on my page and echo the all variables to the screen it does provide me with the proper date format of yyyy-mm-dd.  I've googled all over the place, but cannot seem to find anything dealing with this specific issue.  Perhaps I just suck at the internet... :'(

 

if ($_POST){

// set initial variables 

    $mysqli = mysqli_connect("xxxxxx", "xxxxxx", "xxxxxx", "xxxxxx");
    $day=$_POST['dayNum'];
    $month=$_POST['monthNum'];
    $year=$_POST['yearNum'];
    $fulldate= $year."-".$month."-".$day;

//set the insert query to a variable value

   $case_info = "INSERT INTO caseFile (caseID, caseDate, caseInternal, caseStatus, caseResolution)
   VALUES
    (null,
     ".$fulldate.",
     '".$_POST["internal"]."',
     '".$_POST["status"]."',
     '".$_POST["resolution"]."')";

// run the query and error out if it takes a dump

    $add_case_res = mysqli_query($mysqli, $case_info) or die(mysqli_error($mysqli));
mysqli_close($mysqli);
    $display_block = "<p>Your entry has been added.</p><br />";
}

 

Any help is immensely appreciated!

 

Thanks

-Evo

try this code:

I change a little bit of your code and erase something

if ($_POST){

// set initial variables 

    $mysqli = mysqli_connect("xxxxxx", "xxxxxx", "xxxxxx", "xxxxxx");
    $day=$_POST['dayNum'];
    $month=$_POST['monthNum'];
    $year=$_POST['yearNum'];
    $fulldate= $year."-".$month."-".$day;

//set the insert query to a variable value

   $case_info = "INSERT INTO caseFile (caseID, caseDate, caseInternal, caseStatus, caseResolution)
   VALUES
    (null,'$fulldate',
     '$_POST[internal]',
     '$_POST[status]',
     '$_POST[resolution]')";

// run the query and error out if it takes a dump

    $add_case_res = mysqli_query($mysqli, $case_info) or die(mysqli_error($mysqli));



mysqli_close($mysqli);
    $display_block = "<p>Your entry has been added.</p><br />";
}

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.