0

I have a Javascript variable 'id' which contains a unique network id which I would like access in the PHP code to update my table.

    $("body").on("click", "#" + feature.properties.network_id , function(e) {
    $id = feature.properties.network_id
             layer.setStyle(disable);
             <?php
            $connection = mysqli_connect('localhost', 'root', 'root', 'robsim');
            $sql = mysqli_query($connection,"UPDATE `all_data` SET `Status` = 'Done' WHERE `all_data`.`Network_ID` = id;");
            ?>

    });
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Joel Jogy
  • 17
  • 5
  • 1
    I don't know what you're doing with that code. Use AJAX. – Edward Jun 17 '17 at 22:49
  • Possible duplicate of [Call php function from javascript](https://stackoverflow.com/questions/7165395/call-php-function-from-javascript) –  Jun 17 '17 at 23:44

1 Answers1

0

You can't do it like this. PHP is executed server-side while JavaScript is executed client-side. In other words in this example first your PHP is executed then the JavaScript. You need to do this like this:

$("body").on("click", "#"+feature.properties.network_id , function(e) {
    $id = feature.properties.network_id;
    layer.setStyle(disable);
    $.get('script.php', 'iddd=' + $id); 
});

Then you need to create script.php and put inside it:

<?php
$id = $_GET['iddd'];
$connection = mysqli_connect('localhost', 'root', 'root', 'robsim');
$sql = mysqli_query($connection,"UPDATE `all_data` SET `Status` = 'Done' WHERE `all_data`.`Network_ID` = id;");
?>
Jack
  • 173
  • 1
  • 3