Close

Results 1 to 5 of 5
  1. #1
    DF VIP Member dave208's Avatar
    Join Date
    May 2002
    Location
    mecca
    Posts
    1,002
    Thanks
    0
    Thanked:        0
    Karma Level
    321

    Default submitting current time to database using form

    I'm trying to submit the current date/time to a DATETIME field in an SQL database alongside some text. The text gets entered fine but the date doesn't get submitted at all. Anyone know where I'm going wrong?

    The format of the DATETIME field is 2001-10-27 14:39:49

    What I have so far is...
    PHP Code:
    <? 
    if (isset($_POST['add'])) { 
    $text htmlspecialchars($_POST['text']); 
    $date htmlspecialchars($_POST['date']); 
    if (
    $text != "") { 
    $query "INSERT INTO table1 (text, date) VALUES ('$text', '$date')"
    @
    mysql_query($query); 
    echo 
    "</center>Sucessfully added the following:<p /> 
    $text";} 
    else { echo 
    "Error. All fields must be filled."; }} 
    ?> 
    <form enctype="multipart/form-data" method="post" action="<?php $_SERVER['PHP_SELF']?>"> 
    <input type="hidden" name="date" value="<?php (date("Y/m/d, h:s A")); ?>"> 
    <table> 
    <tr> 
    <td> 
    Text: <textarea rows="7" cols="30" name="text"></textarea> 
    </td> 
    </tr> 
    <tr> 
    <td> 
    <input type="submit" name="add" value="Add Entry"></td> 
    </tr> 
    </table> 
    </form>

  2. #2
    DF Probation Fusen's Avatar
    Join Date
    Mar 2004
    Location
    Kent Uni
    Posts
    3,672
    Thanks
    0
    Thanked:        0
    Karma Level
    565

    Default Re: submitting current time to database using form

    why are you submitting the date as a variable? why not just set $date where you ran htmlspecialchars
    PHP Code:
    <? 
    if (isset($_POST['add'])) { 
    $text htmlspecialchars($_POST['text']); 
    $date date("Y-m-d, h:s A");
    if (
    $text != "") { 
    $query "INSERT INTO table1 (text, date) VALUES ('$text', '$date')"
    @
    mysql_query($query); 
    echo 
    "</center>Sucessfully added the following:<p /> 
    $text";} 
    else { echo 
    "Error. All fields must be filled."; }} 
    ?> 
    <form enctype="multipart/form-data" method="post" action="<?php $_SERVER['PHP_SELF']?>"> 
    <table> 
    <tr> 
    <td> 
    Text: <textarea rows="7" cols="30" name="text"></textarea> 
    </td> 
    </tr> 
    <tr> 
    <td> 
    <input type="submit" name="add" value="Add Entry"></td> 
    </tr> 
    </table> 
    </form>
    [CENTER][FONT=Verdana][SIZE=2]Real pirates don't [I]STEAL[/I], they [/SIZE][/FONT][B][FONT=Verdana][SIZE=2]SHARE[/SIZE][/FONT]
    [/B][SIZE=1]Unless they are cunts, then they just leech...:happy:[/SIZE][/CENTER]

  3. #3
    DF Rookie Joff's Avatar
    Join Date
    Jan 2006
    Location
    UK
    Posts
    2
    Thanks
    0
    Thanked:        0
    Karma Level
    0

    Default Re: submitting current time to database using form

    Have you displayed the contents of $date to see what you're trying to insert into the DB?

    Is your date field in MySQL set as a datetime type?

    What about displaying the contents of $query and then pasting it into MySQL directly to see what it (MySQL) makes of it?

  4. #4
    DF VIP Member dave208's Avatar
    Join Date
    May 2002
    Location
    mecca
    Posts
    1,002
    Thanks
    0
    Thanked:        0
    Karma Level
    321

    Default Re: submitting current time to database using form

    ta fusen mate. had to change 'h:s A' to 'h:s:A' to get it to enter correctly but that little change of not submitting it via the form did the trick nicely. k+

    thanks for the advice aswell joff

  5. #5
    DF VIP Member hxbro's Avatar
    Join Date
    Nov 2000
    Location
    Behind a wall
    Posts
    2,731
    Thanks
    4
    Thanked:        18
    Karma Level
    476

    Default Re: submitting current time to database using form

    I'd have just used the mysql inbuilt function NOW() :

    INSERT INTO table1 (text, date) VALUES ('$text', NOW())
    Download my latest breaks and electro mixes or listen to Sellout Breaks FM

Similar Threads

  1. Whats your favourite Spectrum game of all time?
    By BFG in forum Old Skool Gaming & Retro
    Replies: 92
    Last Post: 20th September 2006, 09:43 AM
  2. where can you buy swords form the uk online?
    By arv2k in forum Home Audio/Video, Electronic Toys & Gadgets
    Replies: 4
    Last Post: 1st October 2002, 04:24 PM
  3. Greatest Movie Of All Time?
    By stei in forum Movie Talk
    Replies: 61
    Last Post: 27th September 2002, 09:40 PM
  4. Travel back in time! when would u go to ?
    By Morph in forum The Dog and Duck
    Replies: 53
    Last Post: 3rd September 2002, 12:54 AM

Social Networking 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
  •