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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    creating a new entry in a table using variales and getDate function

    the variable vlues are:
    $trans_date = getdate();
    $tran_source=5487335;
    $thePswd=1111;
    $theDest=1234567;
    $theAmmount = 20;
    $trans_date2 = getdate();


    the query is:
    if(!mysql_query("insert into transaction(source,destination,amount,date,strt_time,end_time,status)
    values($transSource,$theDest,$theAmmount,trans_date[mday]:$trans_date[mmon]:$trans_date[year],trans_date[seconds]:$trans_date[minutes]:$trans_date[hours],trans_date2[seconds]:$trans_date2[minutes]:$trans_date2[hours],TRUE)")

    {
    echo "query not executed";
    }


    i want the date to be displayed in dd:mm:yy
    i know the prob is in the query syntax but i cant understand how to use the getDate func and also shld i use '$tranSource'??

    data types given when the table was created:

    CREATE TABLE transaction
    (id INT(4) AUTO_INCREMENT NOT NULL PRIMARY KEY,
    source INT(7) UNSIGNED,
    destination INT(7) UNSIGNED,
    amount INT(3) NOT NULL,
    date DATE ,
    strt_time TIME ,
    end_time TIME ,
    status ENUM(\"TRUE\",\"FALSE\") NOT NULL);

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Your code has simple syntax errors that you need to flush out. Be sure to enclose index names with quotes (i.e. $trans_date['hour'], not $trans_date[hour]) and one or two of your variables are missing the dollar sign. You also need to enclose the variables in squiggly brackets when they are complex variables (i.e. {$trans_date['hour']}, not $trans_date['hour']).

    And finally to your point-- the query is an insert query, so it's not going to "display" in any format. Once you have data in a datetime data type, you can format it to be displayed any dang way you feel like with the MySQL function date_format().


  •  

    Posting Permissions

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