0

I am developing the ecommerce website on which i am suck in one place where i am trying to fetch a commission from the sqlserver when admin select the category list and enter price of product , the income of that product what seller will receive should be displayed in another textbox , Here what i have tried till now :

function income_pro(){
    var category=document.getElementById("category").options[document.getElementById("category").selectedIndex].value;
    var produtprice=document.getElementsByName('productprice')[0].value;

    $.ajax({
          method: "POST",
          url: "get_income.php",
          data:  {cat_id: "category", price_id: "produtprice"},

        success: function(data){
            $("#income").html(data); }
        });
}


<form>
  <select type="text" class="form-control" id="category" required>
                        <option value="6">Fashion</option>
   </select>
    <div class="form-group">
                        <label for="product_name">Product Price After Discount(Selling Price)</label>
                        <input type="text" class="form-control" name="productprice" onkeyup="income_pro();" id="productprice" placeholder="Enter Product Price" required>
                      </div>
             <div class="form-group">
                               <label for="product_name">Your Income</label>
                    <input type="text" class="form-control" name="income" id="income"  placeholder="Your Income" disabled>
                             </div>
 </form>

FILE:get_income.php

<?php
  include('includes/config.php');
  if(!empty($_POST["cat_id"]))
  {
     $id=intval($_POST['cat_id']);
     $price=intval($_POST['price_id']);
     $query=mysql_query("SELECT commission FROM category WHERE id=$id");
     while($row=mysql_fetch_array($query))
         {
         $comm = htmlentities($row['commission']);  }
         $income=$price + ($comm/100)*$price;
     }
      ?>

In database i have an table with the name category and row named commission where the commission of the category is written. Here all the code what i have written but i am not getting any output. Can you please help me out!! It will be great help. Thanks in advance

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • You might like to check the browser console for the error messages. They may well help you fix the code errors – RiggsFolly Jul 05 '17 at 16:21
  • What version of JQuery are you using? – RiggsFolly Jul 05 '17 at 16:28
  • 1
    Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[this happens](https://media.giphy.com/media/kg9t6wEQKV7u8/giphy.gif)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions and prepared statements. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Jul 05 '17 at 16:29
  • If you want the PHP code to send data back to the javascript you have to do something with the data to send it. Like `echo $income;` _Not that that is the best way, but at least you might get some data returned that way_ – RiggsFolly Jul 05 '17 at 16:31
  • I am not getting any error in console and the version is jQuery v3.1.1 . @RiggsFolly – Piyush Seofaceup Jul 05 '17 at 16:34

0 Answers0