View Full Version : Quick Date Question

03-23-2008, 01:39 AM
Hey guys...small problem (I assume) this time. Date functions have never worked well with me, but I'm hoping that's not the case for at least some of you. Here's the code I'm using right now:

<input type="text" name="Date" value='<?php echo date("M"); echo " "; echo date("d"); echo ", "; echo date("Y");?>'>

When the page loads, it displays the current date in the textbox, which is good, but when I submit the form, I get an error saying that that variable is undefined. The table that I'm submitting this information into has this variable's column as varchar(100), so I want this input to be a string. Any ideas? Thanks in advance.

03-23-2008, 01:50 AM
Do you have a link to the problem page? If not, please post the full code so that we can see what the issue is.

03-23-2008, 02:06 AM
My apologies, I thought I had pretty well isolated the problem down to that specific line of code. Maybe not. Anyway that input field that I have shown above is submitted (along with other data) to this page to be inserted to the database:

$con = mysql_connect("localhost") or die('Could not connect: ' . mysql_error());
$sql = "create database IF NOT EXISTS Articles";
mysql_query($sql,$con) or die('Could not create database: ' . mysql_error());
mysql_select_db("Articles", $con) or die('Could not select database: ' . mysql_error());
$sql = "create table IF NOT EXISTS Info
pk_Id int unsigned auto_increment,
subject varchar(100) not null,
name varchar(100) not null,
picname varchar(100) not null,
date varchar(100) not null,
article mediumtext not null,
category varchar(100) not null,
primary key(pk_Id),
unique id(pk_Id)
mysql_query($sql,$con) or die('Could not create table: ' . mysql_error());
$S = $_POST['Subject'];
$N = $_POST['Name'];
$P = $_POST['Picname'];
$D = $_POST['Date'];
$A = $_POST['Article'];
$C = $_POST['Category'];
$sql = "INSERT INTO Info (pk_Id, subject, name, picname, date, article, category) VALUES (0,'$S','$N','$P','$D','$A','$C')";
mysql_query($sql,$con) or die('Could not insert data: ' . mysql_error());

03-23-2008, 05:15 PM
Ok so I've been fiddling around with the page, but to no avail. So I figured I'd post the error message too to see if it helps anyone solve this problem:

Could not insert data: Unknown column 'date' in 'field list'

That's what I get when I submit my form. The code for the page is listed above, I'm really lost on this one. So any help would be greatly appreciated. If you know the answer please state it, I'm supposed to have this site done by Monday. Thanks!

03-24-2008, 12:39 PM
<input type="text" name="Date" value='<?php echo date("M"); echo " "; echo date("d"); echo ", "; echo date("Y");?>'>

<input type="text" name="Date" value="<?= date('M d Y',time()); ?>>
if you are putting this into a database table, I would rather suggest that you just put in the current timestamp, as an integer (11) characters. It allows for a lot more control when you will process it later, you will not need to do so much processing.

Either way, you do not need a form field displayed to the browser... when you are running the query to actually insert it into the database, thats when you can put the date in, using whatever format you wish. by putting in on your browser form, you are allowing the user to change the date, therefore not being an accurate depiction of the proper "todays" date