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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:49:45+00:00 2026-05-28T22:49:45+00:00

–Solution found– The correct PHP code is a combination of the two answers provided

  • 0

–Solution found–

The correct PHP code is a combination of the two answers provided below by user1175332 and shanethehat:

Correct HTML Code:

<?php session_start() ?>

<form method="post"  action="session7.php" id="form1">
<input type="text" name="book" value="" id="book"/> Book Box

<input type="submit" value="submit" id="submit" name="submit"/>


</form>

Correct PHP Code:

<?php session_start();
if ($_POST && isset($_POST['book'])) { 
    $_SESSION['book'] = $_POST['book']; 
} 
?>



<?php 

if (isset($_SESSION['book']) && $_SESSION['book'] > 0)

{echo $_SESSION['book'] . ' Book Box(es)';}

else {echo '';}


?>

This works in an isolated test environment. Unfortunately it still doesn’t work with the actual form I’m using, probably because of the javascript it contains.

—– Original Post —–

I have a form in which the user fills out a quantity for different items (1 of X, 4 of Y, etc.) Once the form is submitted, he is taken to the next page, where a price is shown based on the total quantity / volume (this part works thanks to the guys here at StackOverflow).

On the next page, I am trying to have every item that has been filled out (i.e. every item with a quantity greater than 0) be displayed. For instance, if the customer has 1 of X, 4 of Y, but 0 of Z, I want the next page to show:

1 X
4 Y

The form can be seen here. For some reason, I keep getting an “Undefined Index” error.

Here is the PHP code:

<?php session_start();
    if ($_POST && !empty($_POST['TOTAL'])) {
        $_SESSION['TOTAL'] = $_POST['TOTAL'];
    }

    /* this part is the first problematic part*/
    if ($_POST && !empty($_POST['PROD_SP_1.5'])) {
        $_SESSION['PROD_SP_1.5'] = $_POST['PROD_SP_1.5'];
    }
?>
/* end of the first problematic part*/


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
    <title>Untitled 1</title>

</head>

<body>

/* this part is the second problematic part*/
<?php
    if ($_SESSION['PROD_SP_1.5'] > 0) {
        echo $_SESSION['PROD_SP_1.5'] . 'Book Box';
    }
    else {
        echo '';
    }
?>
/* end of the second problematic part*/

<!-- This part posts the total volume in Cubic Feet-->
<?php

    if (isset($_SESSION['TOTAL'])) {
        echo 'Your total volume is ' . round($_SESSION['TOTAL']) . ' Cubic Feet.';
    } else {
        echo 'You did not fill out any details. Please go back.';
    }
?>

<!-- End of volume posting -->

<br/><br/>

<!-- This part posts the correct price based on the total volume -->
<?php
    if ($_SESSION['TOTAL'] > 0 && $_SESSION['TOTAL'] <= 250) {
        echo 'The guaranteed price for door to door service is $1,899.00 based on 1 Section (up to     250CF).';
    } elseif ($_SESSION['TOTAL'] > 0 && $_SESSION['TOTAL'] <= 500) {
        echo 'The guaranteed price for door to door service is $3,349.00 based on 2 Sections (up to 500CF).';
    } elseif ($_SESSION['TOTAL'] > 0 && $_SESSION['TOTAL'] <= 750) {
        echo 'The guaranteed price for door to door service is $4,899.00 based on 3 Sections (up to 750CF).';
    } elseif ($_SESSION['TOTAL'] > 0 && $_SESSION['TOTAL'] <= 1000) {
        echo 'The guaranteed price for door to door service is $5,999.00 based on an exclusive 20ft Container.';
    }
    elseif ($_SESSION['TOTAL'] > 0 && $_SESSION['TOTAL'] <= 1250) {
        echo 'The guaranteed price for door to door service is $7,499.00 based on 5 Sections (up to     1,250CF).';
    }
    elseif ($_SESSION['TOTAL'] > 0 && $_SESSION['TOTAL'] <= 1500) {
        echo 'The guaranteed price for door to door service is $8,599.00 based on 6 Sections (up to 1,500CF).';
    }
    elseif ($_SESSION['TOTAL'] > 0 && $_SESSION['TOTAL'] <= 1750) {
        echo 'The guaranteed price for door to door service is $9,499.00 based on 7 Sections (up to     1,750CF).';
    }
    elseif ($_SESSION['TOTAL'] > 0 && $_SESSION['TOTAL'] <= 2000) {
        echo 'The guaranteed price for door to door service is $9,999.00 based on an exclusive 40ft     Container.';
    }
    else {
        echo 'Sorry, your total volume is too high to quote online. Please contact us to set up an on-    site survey: 1.877.430.1300';
    }
?>

<!-- end of price section -->


</body>

Thanks in advance.

  • 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-28T22:49:46+00:00Added an answer on May 28, 2026 at 10:49 pm

    You need to ensure that the session value has been set, because the condition further up the page means that it is possible for $_SESSION['PROD_SP_1.5'] to not exist:

    /* this part is the second problematic part*/
    <?php
    if (isset($_SESSION['PROD_SP_1.5']) && $_SESSION['PROD_SP_1.5'] > 0) {
    echo $_SESSION['PROD_SP_1.5'] . 'Book Box';
    }
    

    You should also use isset rather than empty when checking id a value exists in the POST array:

    if ($_POST && isset($_POST['PROD_SP_1.5'])) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this code: <?php $valid_ext = array(pdf, doc); $args = array( 'post_type' =>
I would like to count the length of a string with PHP. The string
I've got the following login script.. <?php $name = $_POST[name]; $password = $_POST[password]; $query
My NSXMLParser breaks on this string: <title>AAA &#8211; BCDEFGQWERTYUIO</title> I parsed it in this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a PHP application that stores PHP datetime to my MySQL table. I
I am getting notice on line 30 that twetout is undefined variable <?php $username
So to start, I have an array of XML files. These files need to
I'm struggling to position the second level of a dropdown nav menu and was
Have a webpage that will be viewed by mainly IE users, so CSS3 is

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.