0

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 .

Thanks,

3
Contributors
4
Replies
29
Views
3 Years
Discussion Span
Last Post by diafol
0

Show your code so far. I'm assuming that you don't expect users to do all this for you.

0

hi,
Try this code:

<?php
$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 />
</form>
<h1>Cart Total: $<?php echo $cart; ?></h1>
0

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(){
    id=document.getElementById("company_name").value;

    if (id==""){
        document.getElementById("email_add").value="";
        return;
    }

    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById("email_add").value=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","test.php?id=" + id,true);
    xmlhttp.send();
}
</script>
</head>

<body>
<?php
//$country=intval($_GET['q']);
$link = mysql_connect('localhost', 'root', ''); //changet the configuration in required
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db('test');
//$query="SELECT *  FROM product WHERE ID='$country'";
//$result=mysql_query($query);
?>

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

here is test.php code
<?php
$link = mysql_connect('localhost', 'root', ''); //changet the configuration in required
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db('test');
$id=$_GET['id'];
$sql="SELECT * FROM company WHERE Id=$id";
$sqlresult = mysql_query($sql);
$row=mysql_fetch_array($sqlresult);
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 ,

0

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:

formpage

<form>
...your form controls here...
</form>

<script>
...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...
</script>

handler

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

<script>
//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...
</script>

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