Jump to content

can't insert a date properly


offsprg01

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.