如何将javascript变量转换为php变量?

如何将javascript变量转换为php变量?,javascript,php,html,variables,Javascript,Php,Html,Variables,这是我使用脚本的代码,它是我代码的一部分,我如何将var x放入php中指定的“NULL”值中 enter code here var x = document.getElementById("name_stop"); <?php require_once('dbconnect.php'); $result2=mysql_query("INSERT INTO log (status, code)VALUES('login','NULL')"); ?> 在此处输入代码 var

这是我使用脚本的代码,它是我代码的一部分,我如何将
var x
放入php中指定的“
NULL
”值中

enter code here

var x = document.getElementById("name_stop");

<?php  require_once('dbconnect.php'); $result2=mysql_query("INSERT INTO log (status, code)VALUES('login','NULL')");  ?>
在此处输入代码
var x=document.getElementById(“name_stop”);

除非刷新页面,否则无法将JavaScript变量移动到PHP,因为JavaScript是客户端的,而PHP是服务器端的。加载页面后,PHP的工作就完成了。

您应该了解如何使用ajax


此外,为了应用程序的安全,请始终检查来自客户端的数据。

您正在寻找AJAX。您必须向phpscript发送AJAX请求

发送AJAX请求的最简单方法是使用库


看着你;如果你打算处理数据库查询,你也需要非常小心SQL注入-请停止向这个可怕的网站传播超链接。。。
$.ajax({
  type: "POST",
  url: "insert.php",
  data: { name: x }
})
  .done(function( msg ) {
    alert( "Data Saved: " + msg );
  });