SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Indiana
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Current_date() Current_time() Help Needed!

    I am very new to PHP/MySQL (4 days), old basic programmer that hasn't had a need to kept up till now. And I could use a little help. I have been reading my *** off for the last 4 days trying to get this right but just can't get it.

    So here is my code:

    <?php
    include("global.inc.php");
    $errors=0;
    $error="The following errors occured while processing your form input.<ul>";
    pt_register('POST','Date');
    pt_register('POST','Time');
    pt_register('POST','ReferenceNumber');
    pt_register('POST','Description');
    pt_register('POST','SerialNumber');
    pt_register('POST','R00');
    pt_register('POST','S00');
    pt_register('POST','UnitPrice');
    pt_register('POST','Assigned');
    if($ReferenceNumber=="" || $Description=="" || $SerialNumber=="" || $R00=="" || $S00=="" ){
    $errors=1;
    $error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
    }
    $Date = date("l jS of F Y h:i:s A");
    $Time = date("l jS of F Y h:i:s A");
    if($errors==1) echo $error;
    else{
    $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
    $message="Date: ".$Date."
    Time: ".$Time."
    Reference Number: ".$ReferenceNumber."
    Description: ".$Description."
    Serial Number: ".$SerialNumber."
    R00: ".$R00."
    S00: ".$S00."
    Unit Price: ".$UnitPrice."
    Assigned: ".$Assigned."
    ";
    $message = stripslashes($message);
    mail("forms@my_site.com","Form Submitted at your website",$message,"From: Form Server");
    $link = mysql_connect("localhost","my_username","my_password");
    mysql_select_db("my_db",$link);
    $query="insert into my_table (Date,Time,ReferenceNumber,Description,SerialNumber,R00,S00,UnitPrice,Assigned) values ('".$Date."','".$Time."','".$ReferenceNumber."','".$Description."','".$SerialNumber."','".$R00."','".$S00."','".$UnitPrice."','".$Assigned."')";
    mysql_query($query);

    header("Refresh: 0;url=http://my_webpage");
    ?><?php
    }
    ?>

    Everything works fine except the Current_Date and Current_Time. I can get either all 0000's or an error. Can't figure out what I have wrong.

    This code is a handler script for a form page.

    Any Help would be apreciated
    Thanks
    Jerry


    Sorry forgot to post my MySQL table

    Date date No 0000-00-00
    Time time Yes NULL
    ReferenceNumber varchar(30) No
    Description varchar(25) No
    SerialNumber varchar(12) No
    R00 varchar(11) No
    S00 varchar(13) No
    UnitPrice decimal(6,0) No 0
    Assigned varchar(6) No

  2. #2
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $query="insert into my_table (Date,Time,ReferenceNumber,Description,SerialNumber,R00,S00,UnitPrice,Assigned) values ('".$Date."','".$Time."','".$ReferenceNumber."','".$Description."','".$SerialNumber."','".$R00."','".$S00."','".$UnitPrice."','".$Assigned."')";
    would be apreciated
    Thanks
    Jerry
    I dont know for definate as i am new to php myself but when you insert the date into the database you could use now() to give it the current data and time. i.e

    PHP Code:

    $query
    ="insert into my_table (Date,ReferenceNumber,Description,SerialNumber,R00,S00,UnitPrice,Assigned) values ('NOW()',,'".$ReferenceNumber."','".$Description."','".$SerialNumber."','".$R00."','".$S00."','".$UnitPrice."','".$Assigned."')"
    I dont think you will need the quotes around the NOW().

    Hope this helped!?????

  3. #3
    SitePoint Member
    Join Date
    Sep 2004
    Location
    nw Montana
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Jerry, possible here is the problem?

    ------------
    $Date = date("l jS of F Y h:i:s A");
    $Time = date("l jS of F Y h:i:s A");
    ------------
    Declaring twice?



    Then, i/o work = ??
    ------------------
    Date date No 0000-00-00
    Time time Yes NULL


    Not sure, but worth a try...

    Jim


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
  •