Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8323809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:50:14+00:00 2026-06-08T23:50:14+00:00

I’ve created a discount feature for one of my client. Whenever, a selected coupon

  • 0

I’ve created a discount feature for one of my client. Whenever, a selected coupon is entered into the coupon fiedld, then it will match it from the database that either the coupon is active and does it exist? If yes, then it does some math calculations of giving the user 10% of discount and shows the user, the discounted amount. It works fine in Chrome but when I’m testing the same feature in firefox,, it is behaving so strange. It is giving me around 20%, 50% discount. Like some random maths calculations.

I’m using jquery, php, mysql to show the results in real time to customer. This problem is really teasing me. Initially, I was using PHP sessions to get the discount value but I tried to store the discount value in db and then retrieving it again for calculation. But same prob occurs. I’m so confused at this point.

Here is the jquery code:

<script type="text/javascript">
$(document).ready(function(){
 $("button").click(function(){
    $.post('coupapply.php', {coup:$('#coupon').val()}, function(result) {
    });
    $.post('discount.php', {disc:$('#totamt tr').find("td").eq(1).html()}, function(result) {
    $('#cpresult').html(result);
    });
 });
});
</script>
<span id='cpresult'></span>

Here is the php code:

<?

if ($_REQUEST) {
$disc = $_REQUEST['disc'];
$amt = substr($disc, 1);
$caldisc = $amt*0.1;
$total = (200-$caldisc);
echo "<spain style='font-size:14px;'>*10% discount applied* Pay ".$total." now!</span>";
}
?>

Let me explain this code. The reason I used two $post functions is because I’ve get two values from the current page. One is the coupon code which is set to ‘coup’ and one is the total calculated amount which is set to ‘disc’. Then both values process into different php pages and prints the results.
I think the problem isn’t with PHP code. The prob is with my jquery code. I’ve tried to use some constant values in php code to make calculations like 200-100 and it works fine. But the value of ‘disc’ variable is making a difference.

Problem solved: What was actually happening that I had included an space like this  $200

This space was creating all the problem in firefox browser. So, I was using substr() initially was breaking the string from position 1 but now. I changed the breaking position and set it to 2 and everything is fine now. BTW, thanks for your help guys 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:50:15+00:00Added an answer on June 8, 2026 at 11:50 pm

    PHP is a server-side language. A request is sent to the server and the server runs the PHP code. This means that no matter what browser you have, your PHP code simply CAN NOT return a different result. Same thing goes for your MySQL database. Knowing this, we can pinpoint the problem.

    The problem is in your HTML or javascript (jQuery). Without code, we cant tell where.


    After reading your edit:

    I tried to store the discount value in db and then retrieving it again
    for calculation. But same prob occurs.

    Makes it sounds like something goes wrong when you are handling the response. If you temporarily change your PHP code so it always returns a static value, and the browsers still give a different result, you know it’s your javascript interpreting the values incorrectly.

    If not, we know that the data the browsers sends is different. In both cases, the bug will most likely be in your javascript.

    This is the best answer you’ll get with this little information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I need a function that will clean a strings' special characters. I do NOT
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm making a simple page using Google Maps API 3. My first. One marker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.