php的优惠券代码[关闭]

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 4 years ago.

<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>

I need to make a apply discount work using php or ajax so it will be checked from db and apply a discount and if there is no discount the total payment will come in the bottom one final payment.

</div>

If I understood correctly then you have a table named 'myTable' and a column named 'discount' and another named 'coupon'. Then apply mysql_query to fill the textfield7.

you may use

<?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
?>


If you familiar with mysql then I hope you get it.