jimfog Posted November 8, 2011 Share Posted November 8, 2011 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 More sharing options...
justsomeguy Posted November 8, 2011 Share Posted November 8, 2011 Javascript can't communicate with MySQL, so yeah you need to send the data to PHP first. Link to comment Share on other sites More sharing options...
jimfog Posted November 9, 2011 Author Share Posted November 9, 2011 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 More sharing options...
justsomeguy Posted November 9, 2011 Share Posted November 9, 2011 You can use ajax, you can put the value in a hidden input in a form and submit it, you can redirect and put the value in the URL, etc. It depends on your situation, but there are several ways to get the value to PHP. Link to comment Share on other sites More sharing options...
jimfog Posted November 9, 2011 Author Share Posted November 9, 2011 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 More sharing options...
justsomeguy Posted November 9, 2011 Share Posted November 9, 2011 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 More sharing options...
jimfog Posted November 9, 2011 Author Share Posted November 9, 2011 Thanks for the info Link to comment Share on other sites More sharing options...
artistandlive Posted November 9, 2011 Share Posted November 9, 2011 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 More sharing options...
thescientist Posted November 10, 2011 Share Posted November 10, 2011 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 More sharing options...
jimfog Posted November 10, 2011 Author Share Posted November 10, 2011 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 More sharing options...
justsomeguy Posted November 10, 2011 Share Posted November 10, 2011 I prefer to use int to save timestamps, and I generate the timestamp in PHP from a date string using the mktime function. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.