Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    May 2009
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    What am I doing wrong?

    I would like to have the time and date added to my dB when my form is started. This should be UTC/GMT time.

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">

    <html>
    <head>
      <title>Add entry</title>
    </head>

    <body>
      <a href="add.php">Add entry</a><br>
      <br>
      <?php
      
    /// In order to use this script freely
      /// you must leave the following copyright
      /// information in this file:
      /// Copyright 2012 W4DJD Design
      /// All rights reserved.

      
    include("connect.php");

      
    $query "SELECT * FROM netform ";
      
    $result mysql_query($query);
      
    $num mysql_num_rows ($result);
      
    mysql_close();

      if (
    $num ) {
      
    $i=0;
      while (
    $i $num) {
      
    $date time()+date("Z");
      
    $callsign mysql_result($result,$i,"callsign");
      
    $name mysql_result($result,$i,"name");
      
    $location mysql_result($result,$i,"location");
      
    $msg mysql_result($result,$i,"msg");
      
    $id mysql_result($result,$i,"id");


     
    #echo "<b>date:</b> $date<br>";
      
    echo gmdate("Y/m/d H:i:s",$date);
      echo 
    "<b>callsign:</b> $callsign<br>";
      echo 
    "<b>name:</b> $name<br>";
      echo 
    "<b>location:</b> $location<br>";
      echo 
    "<b>msg:</b> $msg<br>";
      echo 
    "<a href=\"update.php?id=$id\">Update</a> - <a href=\"delete.php?id=$id\">Delete</a>";
      echo 
    "<br><br>";

      ++
    $i; } } else { echo "The database is empty"; }?>
    </body>
    </html>

  • #2
    Regular Coder
    Join Date
    Oct 2011
    Posts
    236
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by djdubuque View Post
    I would like to have the time and date added to my dB when my form is started. This should be UTC/GMT time.

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">

    <html>
    <head>
      <title>Add entry</title>
    </head>

    <body>
      <a href="add.php">Add entry</a><br>
      <br>
      <?php
      
    /// In order to use this script freely
      /// you must leave the following copyright
      /// information in this file:
      /// Copyright 2012 W4DJD Design
      /// All rights reserved.

      
    include("connect.php");

      
    $query "SELECT * FROM netform ";
      
    $result mysql_query($query);
      
    $num mysql_num_rows ($result);
      
    mysql_close();

      if (
    $num ) {
      
    $i=0;
      while (
    $i $num) {
      
    $date time()+date("Z");
      
    $callsign mysql_result($result,$i,"callsign");
      
    $name mysql_result($result,$i,"name");
      
    $location mysql_result($result,$i,"location");
      
    $msg mysql_result($result,$i,"msg");
      
    $id mysql_result($result,$i,"id");


     
    #echo "<b>date:</b> $date<br>";
      
    echo gmdate("Y/m/d H:i:s",$date);
      echo 
    "<b>callsign:</b> $callsign<br>";
      echo 
    "<b>name:</b> $name<br>";
      echo 
    "<b>location:</b> $location<br>";
      echo 
    "<b>msg:</b> $msg<br>";
      echo 
    "<a href=\"update.php?id=$id\">Update</a> - <a href=\"delete.php?id=$id\">Delete</a>";
      echo 
    "<br><br>";

      ++
    $i; } } else { echo "The database is empty"; }?>
    </body>
    </html>
    On the date i would use this:
    PHP Code:
    $date gmdate("Y-m-d H:i:s"); 
    Also do you mean
    PHP Code:
    ++$i should be $i++ 
    Last edited by devinmaking; 01-08-2012 at 11:14 AM.

  • #3
    New Coder
    Join Date
    May 2009
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by devinmaking View Post
    On the date i would use this:
    PHP Code:
    $date gmdate("Y-m-d H:i:s"); 
    Also do you mean
    PHP Code:
    ++$i should be $i++ 
    You maybe right but this doesn't explain how the date will be added to the dB. Right now it only adds 00:00:00:00 to the dB not the current date and time the for was filled in.

  • #4
    Regular Coder
    Join Date
    Oct 2011
    Posts
    236
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by djdubuque View Post
    You maybe right but this doesn't explain how the date will be added to the dB. Right now it only adds 00:00:00:00 to the dB not the current date and time the for was filled in.
    This would not insert into a database, this is just to retrieve the data...

    To insert into a database, as you have used linkes you can do this.

    PHP Code:
    if(isset($_REQUEST["mode"]) && $_REQUEST["mode"] == "add"){

       
    //then enter the insert into database sql query.


    Simply take all the variables and insert into database

    Here is a link to show how to insert into query

    Hope this helps

  • #5
    New Coder
    Join Date
    May 2009
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I think I have that in my added.php file

    PHP Code:
    <a href="index.php">Back to List</a>
    <?php
    /// In order to use this script freely
      /// you must leave the following copyright
      /// information in this file:
      /// Copyright 2012 W4DJD Design
      /// All rights reserved.

    include("connect.php");
    $date trim($_POST['date']);
    $callsign trim($_POST['callsign']);
    $name trim($_POST['name']);
    $location trim($_POST['location']);
    $msg trim($_POST['msg']);

    $query "INSERT INTO netform (id, date, callsign, name, location, msg)
    VALUES ('', '$date', '$callsign', '$name', '$location', '$msg')"
    ;
    $results mysql_query($query);

    if (
    $results)
    {
    echo 
    "Details added.";
    }
    mysql_close();
    ?>

  • #6
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    can i just ask, what are you using the trim function here:

    PHP Code:
    $date trim($_POST['date']);
    $callsign trim($_POST['callsign']);
    $name trim($_POST['name']);
    $location trim($_POST['location']);
    $msg trim($_POST['msg']); 
    shouldnt it be:

    PHP Code:
    $date trim($_POST['date']);
    $callsign trim($_POST['callsign']);
    $name strip_tags($_POST['name']);
    $location strip_tags($_POST['location']);
    $msg strip_tags($_POST['msg']); 
    the reason im leaving the top two as trim is that unless you are calling the date from the form, there isnt really any need to have the $date stripped/trimmed.

    just incase im wrong here, what is the trim function actually for?
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #7
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,090
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Can I just chime in here about storing the date/time in the database..

    Whilst it without a doubt looks pretty to store a date and time in the database in a date and tiem format, it makes things difficult should you wish to sort the rows by the date and time.

    Therefore I always recommend that you store the date and time as a timestamp directly from time() instead. When you pull out that record you can then format it any way you want using date().

    There is an additional avantage to this, you can support users from multiple countries who may want to choose their own timezone in your program. Again using a timestamp gets around this whereas using a pre-formatted date screws that up too.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #8
    New Coder
    Join Date
    May 2009
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Dan13071992 View Post
    can i just ask, what are you using the trim function here:

    PHP Code:
    $date trim($_POST['date']);
    $callsign trim($_POST['callsign']);
    $name trim($_POST['name']);
    $location trim($_POST['location']);
    $msg trim($_POST['msg']); 
    shouldnt it be:

    PHP Code:
    $date trim($_POST['date']);
    $callsign trim($_POST['callsign']);
    $name strip_tags($_POST['name']);
    $location strip_tags($_POST['location']);
    $msg strip_tags($_POST['msg']); 
    the reason im leaving the top two as trim is that unless you are calling the date from the form, there isnt really any need to have the $date stripped/trimmed.

    just incase im wrong here, what is the trim function actually for?
    Removes any excess whitespace on either side of my string. So it would remove any spaces before and after any actual data in the string.


  •  

    Posting Permissions

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