SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    325
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    How to insert time into database

    Hi everybody,

    I have a problem with inserting specific time into Mysql database using a form bellow:

    Code:
    <form method="post" action="insert_time.php">
    	<input type="time" name="time">
    	<input type="submit" value="Insert Time">
    </form>
    When I input data such as 12:00:00, the value is invalid. How to overcome this problem?

    Thanks
    Ket

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,270
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    we would need to see the table definition (do a SHOW CREATE TABLE in mysql) as well as the insert_time.php code
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    325
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    thanks for response, here is it:
    Code:
    $mysqli->query("DROP TABLE IF EXISTS video;") or die("DB error");
    $mysqli->query("CREATE TABLE `video` (
       `vdo_id` INT NOT NULL AUTO_INCREMENT,
       `vdo_path` VARCHAR( 120 ) NOT NULL , 
       `time` TIME NOT NULL  default '00:00:00',
       `title` VARCHAR( 75 ) NOT NULL ,
    PRIMARY KEY ( `vdo_id` ) ,
    UNIQUE (
       `vdo_path`
       )
     ) ENGINE = INNODB
    ")
    or die("DB error!");
    and the insert.php
    Code:
    $title =  trim($_POST['title']);
    $time =  trim($_POST['time']);
    $vdo_path =  basename($title.$length);
    
    $mysqli->query("INSERT INTO video(vdo_path, time, title) VALUES('$vdo_path','$time','$title');") or die(mysqli_error());

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,270
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    this does not explain why the time value is not working

    could you please echo the php query before executing it

    in other words, we need to see the contents of '$time' that mysql sees
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Addict ketting00's Avatar
    Join Date
    Jul 2011
    Posts
    325
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I have no idea. It just didn't work since the <input type="time" name="time">.

    The form didn't pass the value from the input field. The value is blank and it didn't pass the if(empty($_POST['time']) check.

    Additionally, when you use Google chrome it pops up an alert message of 'Invalid Value'.
    Is I use the incorrect form?

  6. #6
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,032
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    A quick search shows the input type "time" to be HTML5, try switching the input type of the form to "text"
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator


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
  •