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 7658409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:11:52+00:00 2026-05-31T13:11:52+00:00

I am getting an error regarding an undefined variable. However, the calculation is correct

  • 0

I am getting an error regarding an undefined variable. However, the calculation is correct and it displays the grand total but the error still appears within the page – here is the error:

Notice: Undefined variable: grand_total in

And here is my code:

$line_cost = $product['price'] * $item['quantity'];
  $grand_total += $line_cost;

  ?>

  <tr>
    <td><?=$product['common_name'];?></td>
    <td><input type='text' name='quantity[]' value='<?=$item['quantity'];?>' size='2' /></td>
    <td>&pound;<?=number_format($line_cost, 2);?></td>
  </tr>
  <!---
    Notice the [] on the field name for quantity - this means it is an array
    The index of the array will start at 0 (i,e. the first product) and the second will be 1, etc...
  --->
  <?php

}
?>
  <!-- Final row to put a button to recalculate -->
  <tr>
    <td colspan='3' align='center'>
      <input type='submit' name='recalc' value='Recalculate' />
    </td>
  </tr>
  <tr>
  <td>&pound;<?=number_format($grand_total, 2);?></td>
  </tr>
</table>

  • 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-05-31T13:11:53+00:00Added an answer on May 31, 2026 at 1:11 pm

    It seems $grand_total variable not defined above.

    $grand_total = isset($grand_total) ? $grand_total : 0;
    $line_cost = $product['price'] * $item['quantity'];
    $grand_total += $line_cost;
    

    Also you can change error reporting to not show notice/warning with error_reporting()

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

Sidebar

Related Questions

I wrote following code...but i am getting Error like: Error 1 'LoginDLL.Class1.Login(string, string, string)':
hi im new to c# and was trying to code but getting error can
Please refer my previous post here . I did changes accordingly but getting error.
I'm getting an error regarding disgarded qualifiers when I use this. The Entier class
I am getting this error Call to undefined function imagecreatefromjpeg() and after reading around
I am getting an error message regarding a styles.xml on my Eclipse for MAC
I'm getting an undefined symbol error even though I think I've defined it okay.
I am new to Java+Maven and PlayN. Please help me regarding following error. Getting
getting error while try to start service
I am getting error trying to run my asp code for executing stored proc.

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.