Results 1 to 5 of 5

Thread: Quick Date Question

  1. #1
    Join Date
    Feb 2006
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Quick Date Question

    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:

    Code:
    <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.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    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.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Feb 2006
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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:

    Code:
    $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());

  4. #4
    Join Date
    Feb 2006
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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!

  5. #5
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Quote Originally Posted by InNeedofHelp View Post
    Code:
    <input type="text" name="Date" value='<?php echo date("M"); echo " "; echo date("d"); echo ", "; echo date("Y");?>'>
    Code:
    <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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •