SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    May 2002
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Insert Time Into MYSQL

    <SCRIPT LANGUAGE="JavaScript">

    RightNow = new Date();
    document.write("It's now " + (RightNow.getHours()) + ":" + (RightNow.getMinutes()) + ", on " +
    RightNow.getDate() + "-" + (RightNow.getMonth()+1) + "-" + RightNow.getFullYear() + ".")

    </SCRIPT>
    This is the code I use to obtain the localtime of my visitors...

    if ($submitmsg == "SUBMIT") {
    $shoutout = "INSERT INTO shoutout SET
    poster='$postername',
    msg='$message',
    time='blablabla'";
    This is the code I use to insert some messages that visitors submitted via the form to a mysql db.

    How can I insert the time that the javascript get from visitors to my mysql db? Can anyone plz help?

  2. #2
    SitePoint Guru Majglow's Avatar
    Join Date
    Aug 1999
    Location
    B-Town
    Posts
    645
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wouldn't you have to go through some server side script? Like PHP or something of that sort?

    -cARL
    Ohai!

  3. #3
    SitePoint Zealot
    Join Date
    May 2002
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah... but I dunno how to insert the javascript string via php and insert it to mysql

  4. #4
    SitePoint Zealot
    Join Date
    May 2002
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    come on, can anyone plz help me?

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:

    <html>
    <head>
    <title> passing vars between JS and PHP </title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta name="mssmarttagspreventparsing" content="true">

    </head>

    <body>


    <?

    echo <<<EOF

    <script language="javascript" type="text/javascript">
    userTime = new Date ();

    function showTime() 
    {
    document.write ('Javascript Output: ' + userTime);
    }

    </script>

    EOF;

    echo 
    "<br><br><br>";

    echo 
    "<br>PHP Output 1: ";
    echo 
    "line 41: " .  $userTime// doesn't work!!!
    echo "<br><br><br>";
    $userTime "<script>document.write(userTime);</script>";
    echo 
    "PHP Output 2 - line 44: " $userTime// works !

    ?>


    <br><br><br>
    JS-Output: <br>
    <script>document.write(userTime);</script>
    <br><br><br>
    PHP, again: <?=$userTime;?>


    </body>
    </html>

    This is just to demonstrate how to define a var and then pass it on to php.

    You can then use e.g.

    SET userTime='$userTime' later on for your DB.

  6. #6
    SitePoint Zealot
    Join Date
    May 2002
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you very much for your instruction... I did successfully define a var and pass it to php and even stored it successfully in mysql ...

    But the problem is, mysql is storing the javascript codes of the var, and load up everytime with a new result.

    My var is something to do with user-end time. so when I load the entries from mysql, everytime it comes out with a new time instead of the time when the entries are inserted, which is wat I intended to do...

    this is how I define the things...
    <SCRIPT LANGUAGE="JavaScript">

    RightNow = new Date()

    <?php

    $usertime = "<script>document.write(RightNow.getHours() + \":\" + RightNow.getMinutes() + \", \" +
    RightNow.getDate() + \"-\" + (RightNow.getMonth()+1) + \"-\" + RightNow.getFullYear() )</script>";

    ?>

    </SCRIPT>
    please advise


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
  •