Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,464 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,395 people online right now. Registration is fast and FREE... Join Now!




date (DATETIME)

2 Pages V  1 2 >  
Reply to this topicStart new topic

date (DATETIME)

iamcenz
post 2 Apr, 2005 - 07:05 PM
Post #1


You wish you were my hand!

Group Icon
Joined: 26 Mar, 2001
Posts: 2,385



Dream Kudos: 201
My Contributions


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.
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>
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 2 Apr, 2005 - 07:37 PM
Post #2


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,173



Thanked 33 times

Dream Kudos: 25
My Contributions


try
CODE

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

Go to the top of the page

iamcenz
post 3 Apr, 2005 - 09:40 AM
Post #3


You wish you were my hand!

Group Icon
Joined: 26 Mar, 2001
Posts: 2,385



Dream Kudos: 201
My Contributions


i did that. it gave me the same error, unless i typed it wrong, ill try it again...
User is offlineProfile CardPM

Go to the top of the page

iamcenz
post 3 Apr, 2005 - 09:43 AM
Post #4


You wish you were my hand!

Group Icon
Joined: 26 Mar, 2001
Posts: 2,385



Dream Kudos: 201
My Contributions


nope no worky, this is the error i get
QUOTE
Column 'blog_date' cannot be null
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 3 Apr, 2005 - 10:16 AM
Post #5


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,173



Thanked 33 times

Dream Kudos: 25
My Contributions


Hmmm...I'm not sure how to proceed...when I have
CODE

<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?
User is offlineProfile CardPM

Go to the top of the page

iamcenz
post 3 Apr, 2005 - 10:27 AM
Post #6


You wish you were my hand!

Group Icon
Joined: 26 Mar, 2001
Posts: 2,385



Dream Kudos: 201
My Contributions


0000-00-00 00:00:00

thats what i see when i view source where the date should be, thats what i see normally.
User is offlineProfile CardPM

Go to the top of the page

iamcenz
post 3 Apr, 2005 - 10:31 AM
Post #7


You wish you were my hand!

Group Icon
Joined: 26 Mar, 2001
Posts: 2,385



Dream Kudos: 201
My Contributions


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.gif
User is offlineProfile CardPM

Go to the top of the page

snoj
post 3 Apr, 2005 - 11:29 AM
Post #8


$Null

Group Icon
Joined: 31 Mar, 2003
Posts: 3,304



Thanked 5 times

Dream Kudos: 700
My Contributions


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

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

Go to the top of the page

iamcenz
post 3 Apr, 2005 - 08:39 PM
Post #9


You wish you were my hand!

Group Icon
Joined: 26 Mar, 2001
Posts: 2,385



Dream Kudos: 201
My Contributions


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

what exactly does
CODE
time()+offset
do? how does it know the offset?
User is offlineProfile CardPM

Go to the top of the page

snoj
post 4 Apr, 2005 - 05:26 AM
Post #10


$Null

Group Icon
Joined: 31 Mar, 2003
Posts: 3,304



Thanked 5 times

Dream Kudos: 700
My Contributions


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. confused.gif I guess I wasn't clear. sad.gif

And if you are interested, I use an offset of 4196 when I need to.
User is offlineProfile CardPM

Go to the top of the page

iamcenz
post 4 Apr, 2005 - 06:06 AM
Post #11


You wish you were my hand!

Group Icon
Joined: 26 Mar, 2001
Posts: 2,385



Dream Kudos: 201
My Contributions


oh ok. thats what i was thinking, but i wasnt sure so i figured i would ask... thanks
User is offlineProfile CardPM

Go to the top of the page

iamcenz
post 4 Apr, 2005 - 08:38 PM
Post #12


You wish you were my hand!

Group Icon
Joined: 26 Mar, 2001
Posts: 2,385



Dream Kudos: 201
My Contributions


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...
User is offlineProfile CardPM

Go to the top of the page

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 11/22/08 01:31PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month