在PHP中折扣优惠券代码

时间:2015-12-16 08:12:04

标签: javascript php ajax



<form id="form1" name="form1" method="post" action="">
  <p>First Name
    <input name="textfield" type="text" id="textfield" value="First name" />
    <br />
  Last Name
  <input name="textfield2" type="text" id="textfield2" value="Last name" />
  <br />
  Total Amount
  <input name="textfield3" type="text" id="textfield3" value="500" />
  <br />
  Discount 
  <input type="text" name="textfield4" id="textfield4" />
  <input type="submit" name="button" id="button" value="Apply Discount" />
  <br />
Discount come here 
<input type="text" name="textfield6" id="textfield6" /> 
(For example if i add a coupan code ABC1 and its discount is in db 10 in this field 10 will come)<br />
Final payment

<input type="text" name="textfield7" id="textfield7" /> (In this payment will come after discount with total amount)

<br />
    Address
    <textarea name="textfield5" id="textfield5"></textarea>
    <br />
    <input type="submit" name="button2" id="button2" value="Submit Form" />
  </p>
</form>
&#13;
&#13;
&#13;

我需要使用php或ajax进行申请折扣工作,以便从数据库中检查并应用折扣,如果没有折扣,则总付款将在最后一笔付款中。

1 个答案:

答案 0 :(得分:1)

如果我理解正确,那么你有一个名为'myTable'的表和一个名为'discount'的列,另一个名为'coupon'。然后应用mysql_query来填充textfield7。

你可以使用

<?php
        //add this tow lines just before your "textField7" input element.

    $sql = mysql_query("select discount from myTable where coupon='ABC1');
        $getValue = mysql_fetch_array($sql);

    //Then add the <input> tag here
?>
        <input type="text" name="textfield7" id="textfield7" value="<?php echo $getValue[0];?>" /> 
<?php
?>


如果你熟悉mysql,那么我希望你能得到它。