Jump to content

Inserting The Time In Mysql


jimfog

Recommended Posts

Is it possible that solely with javascript we can insert the time from the user's computer directly to a database table(MySQL)? Or is it inevitable that we must use php to do the work? As i assume, javascript will take the local time, pass it to php, and php will insert the relevant records to a table? Is the above "flow" correct?

Link to comment
Share on other sites

Ok, following is a question for something i have never done before: Suppose i take the time with js date object.How am i going to pass it to php, i know how to make the connection to the database(once the time gets passed to a php script). So far, the only case i needed to pass data to php was by using an html form-when the user had to enter some data(name, age etc...) Now though, we are talking about something different. So, what is the course of action i must follow?

Link to comment
Share on other sites

Regarding ajax, it is something only now i am beginning to study-so leave it for now. Regarding the form and having the value as hidden.Does that mean that there must be a submit button? Is there a way to submit form data without having a submit button. Submit buttons means that there must be a user action. This is not the case here. regarding the redirect, i will consider it, i do not know how it works, i will study too.

Link to comment
Share on other sites

You can submit a form with Javascript, you don't need a submit button. If you get the form element in Javascript it will have a submit method you can call to submit the form. You can redirect by changing the value of window.location.href.

Link to comment
Share on other sites

Thanks for the info

Link to comment
Share on other sites

You can hide the entire form if you need no visual representation:

<form name="form" id="form" action="YOUR_PHP_FILE" method="..." ...>  <input type="hidden" id="field" name="name" value="YOUR_TIME" /></form><script>  // submit your form (e.g. with jQuery)  $('#form').submit(); </script>

Link to comment
Share on other sites

one might even wonder if a form is necessary. just extra markup when all you really need to do is send a timestamp in a request to the server (which you are getting anyway to put in the hidden form). You can POST/GET to a PHP script via AJAX without using a form.

Link to comment
Share on other sites

Since we have come to such point i cannot hold my self from asking the following question. Ok, either we use AJAX, or a form, finally the time gets sent(through PHP) to the database. Question: SInce we are sending a string, the column of the table where we are sending the time, you think it should be of the VARCHAR type or of the TIME type? Thanks. This question should be going to the MySQL forum but since is very relevant to the original question i decided to make it here.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...