I would like to use a javascript variable that was returned to me by a videoel.getCurrentTime function and convert it to a php variable for me to able to add it up to my SQL Insert Query like INSERT INTO tblData VALUES ('$phpVarFromJavascript');

link|improve this question

75% accept rate
feedback

2 Answers

up vote 4 down vote accepted

You don't "convert" it. Send it using a get request or something similar to the php page.

Javascript runs on the client side while php runs on the server side.

There are many different ways you can do this and which one you choose depends on your particular situation. However, I think it's important to check how this all works and for you to make sure you understand the difference between client side and server side.

Check w3c's example. The Javascript part makes a request to the php file when the user chooses a person. The php file then queries the MySQL database and responds to the Javascript file which then in turns presents the result to the user.

The particular code used in this example I would not recommend using in production. The MySQL database information is stored in plain text which anyone could read. I'm using this link purely as a working example of how everything works together.

link|improve this answer
1  
Just to clarify, w3schools is not affiliated in any way with the w3c. See w3fools.com for more info. – Ktash Jan 16 at 21:58
@Ktash Forgot to add that. I wouldn't recommend w3schools as a great source but it suited the purpose of demonstrating how things work. – Aidanc Jan 17 at 13:38
feedback

JavaScript cannot interact with PHP unless it is via an AJAX request. What you would need to do is send it via AJAX to the page, and then use PHP to access the variable.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.