将Javascript变量转换为PHP变量 [英] Converting Javascript variable to a PHP variable
问题描述
我想使用videoel.getCurrentTime函数返回给我的javascript变量并将其转换为php变量,以便能够将其添加到我的SQL插入查询中,例如INSERT INTO tblData VALUES('$ phpVarFromJavascript');
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');
推荐答案
您不对其进行转换".使用get请求或类似于php页面的东西发送它.
You don't "convert" it. Send it using a get request or something similar to the php page.
Javascript在客户端运行,而php在服务器端运行.
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.
检查 w3c的示例.当用户选择一个人时,Javascript部分会向php文件发出请求.然后,该php文件查询MySQL数据库并响应Javascript文件,然后Javascript文件将结果呈现给用户.
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.
我不建议在本示例中使用在本示例中使用的特定代码. MySQL数据库信息以纯文本格式存储,任何人都可以读取.我仅将此链接用作所有组件如何协同工作的有效示例.
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.
这篇关于将Javascript变量转换为PHP变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!