-1

This is my codes using script, its a part of my codes, how can i put the var x into my VALUES in php, in the specified 'NULL' value?

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')");  ?>
Anna Mae
  • 95
  • 1
  • 10

3 Answers3

5

You can't move JavaScript variables to PHP unless you refresh the page because while JavaScript is client-side, PHP is server-side. When the page is loaded, PHP's job is done.

Anonymous
  • 11,748
  • 6
  • 35
  • 57
1

You should have a look on how to use ajax.

Moreover, for security of your apps, always check the data which are coming from client-side.

Debflav
  • 1,131
  • 7
  • 17
1

You are looking for AJAX. You will have to send a AJAX request to your phpscript.

The easiest way to send an AJAX request is using the jQuery library.

$.ajax({
  type: "POST",
  url: "insert.php",
  data: { name: x }
})
  .done(function( msg ) {
    alert( "Data Saved: " + msg );
  });
Jordi Kroon
  • 2,607
  • 3
  • 31
  • 55