Evollusion Posted August 24, 2009 Share Posted August 24, 2009 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 Link to comment https://forums.phpfreaks.com/topic/171697-solved-using-a-variable-to-insert-a-date/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 24, 2009 Share Posted August 24, 2009 Date values are strings and need to be enclosed in single-quotes in the query. Link to comment https://forums.phpfreaks.com/topic/171697-solved-using-a-variable-to-insert-a-date/#findComment-905377 Share on other sites More sharing options...
merck_delmoro Posted August 24, 2009 Share Posted August 24, 2009 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 />"; } Link to comment https://forums.phpfreaks.com/topic/171697-solved-using-a-variable-to-insert-a-date/#findComment-905382 Share on other sites More sharing options...
Evollusion Posted August 24, 2009 Author Share Posted August 24, 2009 Date values are strings and need to be enclosed in single-quotes in the query. Thanks! That worked perfectly. I knew it was something minute and dumb that I was overlooking! Link to comment https://forums.phpfreaks.com/topic/171697-solved-using-a-variable-to-insert-a-date/#findComment-905431 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.