我正在开发电子商务网站,当我在管理员选择类别列表并输入产品价格<时,我试图从sqlserver获取佣金的地方/ strong>,该产品的收入卖家将收到的应该显示在另一个文本框中,这是我到目前为止所尝试的:
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;
}
?>
在数据库中,我有一个名称类别的表和名为commission的行,其中写入了类别的佣金。这里所有的代码我写的但我没有得到任何输出。能帮帮我吧!这将是很大的帮助。提前致谢