How can i pass the jquery value to php function -


here want call php function parameter held in jquery function.

i have php function takes 1 parameter , executes sql query. , have jquery function getting different values when select item dropdown box.

now want pass value of dropdown box php function, how can this? here have done

$("#product_category").change(function(){     var category = $(this).val(); //getting dropdown value     // here want pass variable value php function }); 

php

    function productmanagement($procat){         // create connection         $conn = new mysqli($servername, $username, $password, $dbname);         // check connection         if ($conn->connect_error) {             die("connection failed: " . $conn->connect_error);         }     $sql = "select product_name,product_category,product_image_url product_list product_category='$procat'";     $result = $conn->query($sql);      if ($result->num_rows > 0) {         // output data of each row         while($row = $result->fetch_assoc()) {         echo "<tr><td>". $row["product_name"]."</td><td><a href=''><span class='glyphicon glyphicon-remove'></span>remove</a></td><td><a href='edit-product.php'><span class='glyphicon glyphicon-edit'></span>edit</a></td></tr>";         }     } else {         echo "no results found";     }     $conn->close(); } 

how can this?

another way use ajax :

jquery code:

$("#product_category").change(function(){     var category = $(this).val(); //getting dropdown value     // here want pass variable value php function  ----------------------------------------------------- $.ajax({   url: 'newfunctionfile.php',   type: 'post',   data: 'category='+category,   success: function(data) {     //you can add code show success message    },   error: function(e) {     //called when there error     //console.log(e.message);   } });  }); 

and have create file php function let file name newfunctionfile.php have mention in ajax call:

if(isset($_post['category'])) {                     productmanagement($_post['category']);     }   function productmanagement($procat){         // create connection         $conn = new mysqli($servername, $username, $password, $dbname);         // check connection         if ($conn->connect_error) {             die("connection failed: " . $conn->connect_error);         }     $sql = "select product_name,product_category,product_image_url product_list product_category='$procat'";     $result = $conn->query($sql);      if ($result->num_rows > 0) {         // output data of each row         while($row = $result->fetch_assoc()) {         echo "<tr><td>". $row["product_name"]."</td><td><a href=''><span class='glyphicon glyphicon-remove'></span>remove</a></td><td><a href='edit-product.php'><span class='glyphicon glyphicon-edit'></span>edit</a></td></tr>";         }     } else {         echo "no results found";     }     $conn->close(); } 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -