Jump to content

Recommended Posts

I am building a web price updates page for an e-commerce website, and would like to create a form where I can update products within the product group selected(via a drop down menu), by any percentage that is input by the user. There are 200 different product groups all containing a list of products that are stored within a database that is already connected to the webpage and displays a list of products, web price etc. I would like to be able to select a particular group from the drop down menu, then apply the percentage increase, that the user has input into the form through the text box, to the group of products selected.

 

Hope this makes sense any help would be greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/260725-form-to-increase-value-by-a-percentage/
Share on other sites

I have now got slightly further with this and have created an update form for this. The update form currently ouputs the new web price as a 40% increase as I have set it to do this. I would like a way to have a value input by the user (as the percentage increase) in place of the calculation for 40% percent increase so that it can be any number from the text box.

 

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {

  $updateSQL =

sprintf("UPDATE ProductsUpdated

SET Web_Price=round((Web_Price)*1.40,2) // This is where I need my calculation for any percentage increase 

WHERE SageGroup='$sgroup'",

GetSQLValueString($_POST['Web_Price'], "text"),

GetSQLValueString($_POST['SageGroup'], "text"));

Take whatever number they enter into the field, verify it is a number, and then convert it to a decimal percentage.  For example:

 

<?php
$currentPrice = 54.99;

if (isset($_POST['percent'])){
   if (ctype_digit($_POST['percent'])){ 
       $percent = intval($_POST['percent']);
       $percent /= 100; // Convert it from say 40 to 0.40
       
        if ($_POST['type']=='+'){ $percent += 1; }
        else { $percent = 1 - $percent; }
       
       //Now $percent will be say 1.40 if an increase or .60 if a decrease
       //Just multiply it by  the current price.
      echo $currentPrice * $percent;
   }
}

?>

<form action="" method="post">
Enter percent: <input type="text" name="percent">%
Type: <select name="type"><option value="+">Increase</option><option value="-">decrease</option></select>
</form>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.