From MYSQL DB to Textbox Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jrhitokiri
    New Member
    • Apr 2008
    • 35

    From MYSQL DB to Textbox Problem

    usually, when i have questions regarding my DB systems, i just google, and i always find this forum very helpful, so i decided to join this forum and ask this question i coulndt find on the net, 'coz i think you guys know a lot about this:

    I have this Datetime field in my mysql DB, which i queried with the SELECT command. now in my page, i have this input field for datetime. in this input box, i would like to place the value in my MYSQL DB as a default value, but when i tried to do this:

    [PHP]
    <input type="text" name="date_time " value =<? printf("%s",$da te_time); ?> >
    [/PHP]

    it only outputs the date, and not include the time.
    i tried to output what was in the variable before the input box and what i got was this:

    2008-04-02 10:30:00

    but in the box, it only showed

    2008-04-02.

    here's the select statement and php code i used at the top of the page.. what am i doing wrong?
    Code:
    SELECT DATE_FORMAT(date_time,'%Y-%m-%d %H:%i:%s'),
    FROM project WHERE project.ctrl_no = '$proj_id'
    [PHP]$date_time = $row[0];[/PHP]
    Last edited by jrhitokiri; Apr 3 '08, 01:14 AM. Reason: php and code tags
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Since there are 'strange' characters in the value field, like a blank, you have to enclose the value in the input statement within quotes. Like this[php]<input type="text" name="date_time 1" value ="<? printf("%s",$da te_time); ?>" >

    or

    <input type="text" name="date_time 2" value ="<? echo "$date_time ;" ?>" >[/php]Ronald

    Comment

    • jrhitokiri
      New Member
      • Apr 2008
      • 35

      #3
      Originally posted by ronverdonk
      Since there are 'strange' characters in the value field, like a blank, you have to enclose the value in the input statement within quotes. Like this[php]<input type="text" name="date_time 1" value ="<? printf("%s",$da te_time); ?>" >

      or

      <input type="text" name="date_time 2" value ="<? echo "$date_time ;" ?>" >[/php]Ronald

      i see.. il try this one out.. ill come back here if i have some more problems. thanks!:D i really appreciate it.

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Glad I could assist. See you around.

        Ronald

        Comment

        Working...