how to POST the form button click time to PHP?

For the following button action,  I cannot able to post the "new Date();" to PHP and into the DB...  Bascially i am trying to send the button click time-stamp to Database. How do I POST the button click time to PHP?


 <?php
$baction = pg_escape_string($_POST['baction']);


$sql = "INSERT INTO table VALUES('$baction');";

 ?>

<FORM action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >

<input type="baction" value="Action" name="baction" onclick="init(); new Date();">

</FORM>
MikeAnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Paul-BCommented:
Is there a long time between the clicking of the button and the processing to the DB or something? I mean couldn't you just call the date("ymd") at the time of the actual INSERT?
0
maeltarCommented:
Are you wanting to insert the timestamp of when the button was clicked or when the record is inserted ?

if the latter you could use :

$sql = "INSERT INTO table VALUES(NOW())";

but you need to ensure the datatype of the column is datetime
0
IronhoofsCommented:
The button itself is not posted. You can declare another input and change the value of this input when the button is clicked. For example:

<FORM name="navForm" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
   <input type="hidden" name="baction" value="">
   <input type="submit" value="Action" onclick="document.navForm.baction.value=new Date().getTime();">
</FORM>

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

IronhoofsCommented:
In my example i used "new Date().getTime()" because it returns milliseconds elapsed sinds 1-1-1970, while "new Date()" only returns full seconds. Use what best suits your needs.

Also remember that anything posted is a string and you have to format/convert it to the
correct type before inserting it into the database.
0
Ray PaseurCommented:
This article contains information about how to get the client date and time through a form.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391-PHP-login-logout-and-easy-access-control.html
0
MikeAnalystAuthor Commented:
Yes “Paul-B”, there is a time gap between (baction) button click and final form SUBMIT button click.

Yes, “maeltar” I am able to capture the final submit button time with the following php-postgresql connection code

$sql = "INSERT INTO users VALUES (clock_timestamp());

But here, I also wanted to capture the timestamp when user click “baction” button.



<input type="baction" value="Action" name="baction" onclick="init(); new Date();">

When user click “baction” button, it call the JavaScript function init() and it works great, but also I want to capture the button click time at the same time

Within the javascript file where init() reside, I tried to insert the following

Function currenttime()
{
var bclicktime = new Date()
}

And try to POST to PHP sometime like $btime = pg_escape_string($_POST[‘baction’]);

I could be a small little thing but I am not thinking correctly… Basically I want the “baction” button to execute “init();” function (it is working great) at the same time want to capture the button click timestamp POST to PHP and pass it down to Postgresql.
0
Ray PaseurCommented:
Go to the article posted above and read the paragraphs captioned:
Storing Date and Time in Your Database
PHP and MySQL Have Different Time Zone Settings (Test on your system to see if this is also applicable to PostGreSQL - I would expect that it is applicable)
Practical Application #8
0
MikeAnalystAuthor Commented:
"Ray_Paseur"
I didn't find anyting in the above link but I checked section "Practical Application #8" in your "Handling Date and Time in PHP and MySQL" article.

$client_offset_minutes = $_POST["date_O"];

<form method="post">
<input name="date_O" id="dateTime_O" type="hidden" />
<input type="submit" value="CHECK CLIENT DATETIME" />
</form>

<script type="text/javascript">
var dateObject = new Date();
document.getElementById("dateTime_O").value =dateObject.getTimezoneOffset();
</script>


The above code seems like for page load not for button click.
I didn't try yet, but if I replace type="hidden" with "button" should this POST button click timestamp to "$client_offset_minutes"?

<input type="button' name="date_O" id="dateTime_O" onlick="init();" />
0
MikeAnalystAuthor Commented:
It is not working for me, any help on capturing the button click time (not submit button click time).
0
StingRaYCommented:
Like this?

<FORM name="navForm" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
   <input type="button" name="baction" value=""  onclick="this.value=new Date().getTime();">
</FORM>

Open in new window

0
MikeAnalystAuthor Commented:
After serveral tries, I am coming to a conclusion that we cannot use second BUTTON within the same FORM that has SUBMIT button to POST data to PHP...
When I change the type="button" to type="radio" the problem is gone. I still like to use the button as it is more user friendly, I guess i am stuck with "radio/checkbox" type.  I might be wrong, if I am wrong please do correct me.


 <?php
$baction = pg_escape_string($_POST['baction']);
$sql = "INSERT INTO table VALUES('$baction');";

echo .$baction.;
 ?>

<FORM action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
<input type="radio" value="Action" name="baction" onclick="init();" onmouseup="this.value=new Date();">

<input .....
<input .....
<input .....
<input .....

<input type="submit" name="submit" value="SET">
</FORM>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IronhoofsCommented:
I have completly lost you there. You can have several submit buttons in a form, but what problem does the radio button solve that the submit button didn't?
0
MikeAnalystAuthor Commented:
For my situation, chaning type="button" to type="radio" worked. Unfortunatly i cannot use multiple submit button, just wanted to use regular button.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.