12 Replies - 2210 Views - Last Post: 05 April 2005 - 06:58 AM Rate Topic: -----

#1 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

date (DATETIME)

Posted 02 April 2005 - 08:05 PM

ok, so i have a hidden feild on my form that is suppose to send the date to a database not working to well. the feild in the database is a DATETIME blob. i want it to look something like this 04.02.05 09:10pm i tried setting the value in the hidden feild to <? date("m.d.y,h:i:a"); ?> but that didnt work.. it said that blog_date could not be null... this is the code.
<?php require_once('../Connections/conn.php'); ?>
<?php
session_start();
$MM_authorizedUsers = "4";
$MM_donotCheckaccess = "false";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && false) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "../login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?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"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO bbn_blog (blog_id, blog_title, blog_text, blog_date, blog_author) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['blog_id'], "int"),
                       GetSQLValueString($_POST['blog_title'], "text"),
                       GetSQLValueString($_POST['blog_text'], "text"),
                       GetSQLValueString($_POST['blog_date'], "date"),
                       GetSQLValueString($_POST['blog_author'], "text"));

  mysql_select_db($database_conn, $conn);
  $Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());

  $insertGoTo = "../index.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<input name="blog_id" type="hidden" id="blog_id">
<br>
Title:
<input name="blog_title" type="text" id="blog_title">
   <br>
   Entry:<br>
   <textarea name="blog_text" cols="60" rows="10" id="blog_text"></textarea>
   <br>
   <input name="blog_date" type="hidden" id="blog_date">
   <input name="blog_author" type="hidden" id="blog_author" value="<?=$_SESSION['MM_Username']?>">
   <br>
   <input type="submit" name="Submit" value="Submit">
   <input type="reset" name="Reset" value="Reset">
   <input type="hidden" name="MM_insert" value="form1">
</form>
</body>
</html>



Is This A Good Question/Topic? 0
  • +

Replies To: date (DATETIME)

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: date (DATETIME)

Posted 02 April 2005 - 08:37 PM

try
<input type="hidden" name="date" value="<?=date("m.d.y,h:i:a"); ?>">


Was This Post Helpful? 0
  • +
  • -

#3 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: date (DATETIME)

Posted 03 April 2005 - 10:40 AM

i did that. it gave me the same error, unless i typed it wrong, ill try it again...
Was This Post Helpful? 0
  • +
  • -

#4 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: date (DATETIME)

Posted 03 April 2005 - 10:43 AM

nope no worky, this is the error i get

Quote

Column 'blog_date' cannot be null

Was This Post Helpful? 0
  • +
  • -

#5 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: date (DATETIME)

Posted 03 April 2005 - 11:16 AM

Hmmm...I'm not sure how to proceed...when I have
<input name="blog_date" type="hidden" id="blog_date" value="<?=date("m.d.y,h:i:a"); ?>">


on my system, the date is there...I hate to ask, but you have used the equal sign, right?

It may be getting lost between generation and database entry...you may have to track it (echo it to the screen) every step of the way.

First step: What do you see for the value parameter of blog_date when you do a 'View Source' on the page?
Was This Post Helpful? 0
  • +
  • -

#6 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: date (DATETIME)

Posted 03 April 2005 - 11:27 AM

0000-00-00 00:00:00

thats what i see when i view source where the date should be, thats what i see normally.
Was This Post Helpful? 0
  • +
  • -

#7 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: date (DATETIME)

Posted 03 April 2005 - 11:31 AM

ok it works, it was a problem on my part, i typed somethign wrong. i had bloh_date not blog_date... stupid typos... sweet only thing now is its the wrong time and date lol. its a month off and 2 hours slow lol :crazy:
Was This Post Helpful? 0
  • +
  • -

#8 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: date (DATETIME)

Posted 03 April 2005 - 12:29 PM

You're running off of Mg1 hosting right? I have the same problem...only mine is just more then an hour.

Anyway try:
<input name="blog_date" type="hidden" id="blog_date" value="<?=date("m.d.y,h:i:a", time()+Offset); ?>">

Was This Post Helpful? 0
  • +
  • -

#9 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: date (DATETIME)

Posted 03 April 2005 - 09:39 PM

yeah im MG1 mine is an hour and like 15 minutes.

what exactly does
time()+offset
do? how does it know the offset?
Was This Post Helpful? 0
  • +
  • -

#10 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: date (DATETIME)

Posted 04 April 2005 - 06:26 AM

Offset is integer of the time in seconds that your server is behind...so you get the real time. I just put offset instead of some number hoping you'd get my point. :/ I guess I wasn't clear. :(

And if you are interested, I use an offset of 4196 when I need to.
Was This Post Helpful? 0
  • +
  • -

#11 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: date (DATETIME)

Posted 04 April 2005 - 07:06 AM

oh ok. thats what i was thinking, but i wasnt sure so i figured i would ask... thanks
Was This Post Helpful? 0
  • +
  • -

#12 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: date (DATETIME)

Posted 04 April 2005 - 09:38 PM

ok i did the exact code you have me and even used the same offset as you, just to see how close it comes to mine. but it didnt do anything...
Was This Post Helpful? 0
  • +
  • -

#13 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: date (DATETIME)

Posted 05 April 2005 - 06:58 AM

Dangit. *ponders what could be wrong*

have you tried:
<?php echo date("m.d.y,h:i:a", time()+4196); ?>


Try that 'cuz I've never had much luck doing "unorthodox" methods like <?=something() ?> on MG1 servers. If that doesn't work...I don't know what will. :/

This post has been edited by hotsnoj: 05 April 2005 - 06:59 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1