如何将javascript变量传递给php mysql select查询?

时间:2017-11-01 10:55:06

标签: javascript php mysql ajax

我需要获取'val'的值并在我的MYSQL查询的WHERE子句中使用它我该怎么做? ##

<script>
   function myFunction(val) {
   alert("The input value has changed. The new value is: " + val);

   **var var1 = val;
   $.ajax({
        url: 'your_script.php',
        type: 'POST',
        data: {var1: javascript_var_1},
        success: function(data) {
            console.log("success");
        }
    });**
  

这是我放置ajax代码的地方。

   var ele = document.getElementById('insertHere');
   ele.innerHTML = '<input class="form-control" name="fullname" placeholder="Student Full Name"
   value="<?php 

      $var1 = $_POST['var1'];                                              


     $query = "SELECT * FROM student WHERE studentID = '$var1' ";
     $result = mysqli_query($con,$query);
     $row = mysqli_fetch_array($result);
     echo $row['fname'].' '.$row['mname'].' '.$row['lname'];



    ?>" readonly/>';



  }
 </script>

0 个答案:

没有答案