Dear all ,

I want a purchase order form where item , description ,unit price , quantity and amount an additional on load discount field has to be present which will be disabled from putting inputs . The value will directly come from the database depending upon the count value which will be provided by the user .

The relevant database for the count too is also attached herewith .

Secondly , at the top of the form there is a link written as "Show Customization Actions" .

when it is clicked , a special checkbox called "special discount" (in place of the "tax")should be available when checked will add a "special discount " column to the existing form .

Database Format are as given as follows :

From the product table : Product id , Product name & Unit Price.

From the volume table : Volume(Count) and Discount.

If count is from 1 to 5 , corresponding discount will come from database as 10 %.
if count is from 6 to 10 , corresponding discount will come from database as 12 %.
if count is from 11 to 20 , corresponding discount will come from database as 15 %.

Example link is: http://www.aynax.com/freeEstimateTemplate.php
Your help on the above will be highly felicitated and oblige .


3 Years
Discussion Span
Last Post by diafol

Try this code:

$cart = 0;

 if (isset($_POST['submit'])) {

  $samples = ($_POST['sample_']) * 50;
  $cart = $cart - $samples;
<form action="echo.php" method="post">
<input type="hidden" value="1" name="sample_" id="sample_">
Sample Bottle  <br />
<input type="submit" value="Add to Cart" name="submit"><br />
<h1>Cart Total: $<?php echo $cart; ?></h1>

Hi ,
Sorry I could not post the code. I got a code from this forum but not working .Please look ...

<script type="text/javascript">
function showEmail(){

    if (id==""){

    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
    xmlhttp.open("GET","test.php?id=" + id,true);

$link = mysql_connect('localhost', 'root', ''); //changet the configuration in required
if (!$link) {
    die('Could not connect: ' . mysql_error());
//$query="SELECT *  FROM product WHERE ID='$country'";

$query="SELECT * FROM company";
$result3 = mysql_query ($query); ?>
<select name="company_name" class="formfield" onChange="showEmail();">
    $id = $row['Id'];
    $company_name = $row['company_name']; 
<option value="$id"><?php echo $company_name; ?></option>
<input type="text" name="email_add" id="email_add" value="" />

here is test.php code
$link = mysql_connect('localhost', 'root', ''); //changet the configuration in required
if (!$link) {
    die('Could not connect: ' . mysql_error());
$sql="SELECT * FROM company WHERE Id=$id";
$sqlresult = mysql_query($sql);
echo $row['email_add'];


similar way I want product will be selected from dropdown and corresponding price will come from database to display on input box.

Thanks ,


OK, so what bit isn't working? Can you narrow it down?

You're going to use ajax. Are you aware of how it works?
Usually you have these parts:


...your form controls here...

...ajax script here - gets values from the form and sends them to another file (let's call it handler.php) and waits for a "response". When a valid reponse returns, you update the form (or another part of the page) with that data...


accept data from js script (either as $_GET or $_POST - you decide what's best - but if you're just looking up values in a DB and not changing anything in the DB, use GET).
Use the data in the $_GET variable to extract data from the DB using an SQL query. Echo the output (or echo the json encoded data if you're want json returned - probably not in your case).

You may think I'm being deliberately awkward, but I'm trying to show you the nuts and bolts of an ajax call. jQuery and other libraries make ajax calls very easy, so you may find it/those useful.

You may find tht an ajax call is not required if you always have the same criteria for discount - it could all be done just in js:

Use js to find the number of products in the form and apply a static rule...

//get count from your form
var count = ...?;
var discount = 0;
if(count > 10){
    discount = 0.15;
}elseif(count > 5){
    discount = 0.12;
}elseif(count > 0){
    discount = 0.1;
...do something...

As this data is 'public', all data should be considered suspect as a malicious user could change the discount to anything they want - so, you MUST check discount values against count products server side (php) too.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.