offsprg01 Posted February 26, 2007 Share Posted February 26, 2007 here's the scrpit that generates a date <?php echo date('m-d-Y'); ?> here's the script that puts it in the db 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; } if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE PressReleases SET Title=%s, Body=%s, PubDate=%s WHERE ID=%s", GetSQLValueString($_POST['Title'], "text"), GetSQLValueString($_POST['Copy'], "text"), GetSQLValueString($_POST['PubDate'], "text"), GetSQLValueString($_POST['PRID'], "int")); } but every time i run the script the date in the db is the default date. the db is set up to give a default value of 0000-00-00. Link to comment https://forums.phpfreaks.com/topic/40097-cant-insert-a-date-properly/ Share on other sites More sharing options...
btherl Posted February 26, 2007 Share Posted February 26, 2007 Try Y-m-d format instead of m-d-Y. Computers don't like m-d-Y because it's not in order. Link to comment https://forums.phpfreaks.com/topic/40097-cant-insert-a-date-properly/#findComment-194003 Share on other sites More sharing options...
christo16 Posted February 26, 2007 Share Posted February 26, 2007 maybe try now() instead of $_POST['PubDate'] Link to comment https://forums.phpfreaks.com/topic/40097-cant-insert-a-date-properly/#findComment-194004 Share on other sites More sharing options...
offsprg01 Posted February 26, 2007 Author Share Posted February 26, 2007 can't use now() becuase the user can change the date from today's date. i'll try the Y-m-d thing. but theart director has specified the the date needs to be m-d-Y. Link to comment https://forums.phpfreaks.com/topic/40097-cant-insert-a-date-properly/#findComment-194008 Share on other sites More sharing options...
offsprg01 Posted February 26, 2007 Author Share Posted February 26, 2007 evern with a Y-m-d date is stil returns the defalt value. Link to comment https://forums.phpfreaks.com/topic/40097-cant-insert-a-date-properly/#findComment-194018 Share on other sites More sharing options...
AndyB Posted February 26, 2007 Share Posted February 26, 2007 All I see is something to construct a query string. I don't see the query executed in your code. When testing, it never hurts to echo the query string which might not be exactly what you expect. Add error display to any query execution as well. Link to comment https://forums.phpfreaks.com/topic/40097-cant-insert-a-date-properly/#findComment-194037 Share on other sites More sharing options...
offsprg01 Posted February 26, 2007 Author Share Posted February 26, 2007 here's the full code for another page with the same issue. it seems i can't get any dates to insert correctly. <? $FilePath = '../'; require ('../includes/header.inc'); ?> <?php require_once('../Connections/TestDB.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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']); } $uploadNotice = "No File Uploaded Yet"; if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { // Where the file is going to be placed $target_path = "uploads/"; $filename = basename( $_FILES['uploadedfile']['name']); $_FILES['uploadedfile']['tmp_name']; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $_FILES['uploadedfile']['tmp_name']; if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { $uploadNotice = "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded.<br />"; } else{ $uploadNotice = "There was an error uploading the file, please try again!<br />"; } //now we save the file location and info in the database $insertSQL = sprintf("INSERT INTO PromoImages (FileName, StartDate, EndDate, `Default`, LeftRight) VALUES (%s, %s, %s, %s, %s)", GetSQLValueString($filename, "text"), GetSQLValueString($_POST['StartDate'], "date"), GetSQLValueString($_POST['EndDate'], "date"), GetSQLValueString($_POST['Default'], "int"), GetSQLValueString($_POST['LeftRight'], "int")); mysql_select_db($database_TestDB, $TestDB); $Result1 = mysql_query($insertSQL, $TestDB) or die(mysql_error()); $insertGoTo = "ticker_create.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } ?> <div id="content"> <? require ('../includes/exploreNav.inc'); ?> <div id="mainContent"> <div align="left"><span class="contentHeader">UPLOAD A NEW TICKER</span></div> <br /> <img src="../images/common/dottedLine.gif" alt="dottedline" width="480" height="6" /><br /><br /> <p>Please fill out the information below.</p> <div class="mainContentHeading">Upload A New Ticker</div> <div class="mainContentBody" style="padding-top:5px; padding-bottom:5px; padding-right:30px; text-align:right"> <form enctype="multipart/form-data" method="post" name="form1" action="<?php echo $editFormAction; ?>"> <div style="float:right" align="left"> <input type="text" name="LeftRight" value="" size="32" /> <br /> <input type="hidden" name="URL" value="" size="32"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> <input name="uploadedfile" size="32" type="file" /><br /> <?php if ($uploadNotice == "No File Uploaded Yet") { echo "File needs to be a .jpg or .gif (353 pixels wide and 65 pixels high)<br />"; } else { echo $uploadNotice; } ?> <input type="text" name="StartDate" value="<?php echo date('m-d-Y') ?>" size="32"><br /> <input type="text" name="EndDate" value="<?php echo date('m-d-Y') ?>" size="32" /><br /> <input type="text" name="Default" value="" size="32"><br /> <input type="hidden" name="MM_insert" value="form1"> </div> <div style="line-height:17pt; padding-top:3px"> Position Graphic: <br /> Choose file to upload: <br /><div style="line-height:15pt"><br /></div> Start Date: <br /> End Date: <br /> Default Image: </div> <br clear="all" /> <input type="submit" style="background-color:#000066; color:#FFFFFF; border:none; font-size:10px; margin-top:5px" value="Upload File"> </form> </div> <p> </p> <img src="../images/common/dottedLine.gif" alt="dottedline" width="480" height="6" /><br /> <p> </p> </div> <div id="contentOrangeBar"><img src="../images/common/inside_bar.gif" width="549" height="16" alt="inside bar" /></div> <!--This forces all content to scale with the medium--> <div style="clear:both;"> </div> </div> <? require ('../includes/footer.inc'); ?> Link to comment https://forums.phpfreaks.com/topic/40097-cant-insert-a-date-properly/#findComment-194130 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.