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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:59:43+00:00 2026-06-12T05:59:43+00:00

I’m setting up 2 text-boxes and one drop down options list in html. I’m

  • 0

I’m setting up 2 text-boxes and one drop down options list in html. I’m trying to use php to validate if these text box are filled in or not. If clicked on the submit button (‘btnCalculate’), the validation occurs, if nothing in the text boxes, there will be an error message that pops up beside it (‘pamountErrorMsg, irateErrorMsg’). If there is substance that is typed into the textboxes, the browser will save the information into Session[“pamount”] or “irate”. I am having trouble validating the blank text boxes and adding the variables into Session before I can use them in the next page. Right now it is not validating anything at all. What is wrong with my syntax, if any?

Was thinking of using just using
“php? $pamount = $_SESSION[“pamount”]; ?>” to create the variable I need to read the session variable, is that correct?

PHP

session_start();    // start PHP session! 

header('Cache-Control: no-cache');
header('Pragma: no-cache');

$pamountErrorMsg = "";
$irateErrorMsg = "";

$btnCalculate = $_GET['btnCalculate'];
$irate = $_GET['irate'];
$pamount = $_GET['pamount'];    
    $y2d = $_GET['y2d'];
if(isset($btnCalculate))
{
    if(strlen(trim($pamount)) <= 0)
    {
        $pamountErrorMsg = "Principal Amount cannot be empty";
        $irateErrorMsg = "";
    }
    else if(strlen(trim($irate)) <= 0)
    {
        $irateErrorMsg = "The interest rate cannot be empty";
        $pamountErrorMsg = "";
    }
    else
    {
        $_SESSION["pamount"] = $_GET["pamount"];
        $_SESSION["irate"] = $_GET["irate"];
                    $_SESSION["y2d"] = $_GET["y2d"];
        header("Location: Lab3DisclamerZCL.php");
        exit( );
    }
}
?> 

HTML

<form method='get' action="Result.php">
<table>
    <tr>
        <td>
        Principal Amount
        </td>
        <td>
        <input type='text' class='input' name='pamount' size='30' />
        </td>
        <td class='error'>
        <?php echo $pamountErrorMsg; ?>
        </td>
    </tr>
    <tr>
        <td>
        Interest Rate (%)
        </td>
        <td>
        <input type='text' class='input' name='irate' size='30' />
        </td>
        <td class='error'>
        <?php echo $irateErrorMsg; ?>
        </td>
    </tr>
    <tr>
        <td>
        Years to Deposite
        </td>
        <td>
        <select name='y2d' selected='5'>
                <option value='1'>1</option>
                <option value='2'>2</option>
                <option value='3'>3</option>
                <option value='4'>4</option>
                <option value='5' selected='selected'>5</option>
                <option value='6'>6</option>
                <option value='7'>7</option>
                <option value='8'>8</option>
                <option value='9'>9</option>
                <option value='10'>10</option>
        </td>
    </tr>
        <tr>
            <td>&nbsp;</td>
            <td>
                <input type='submit' class='button' name='btnCalculate' value='Calculate'/>&nbsp;&nbsp;
                <input type='reset' class='button' name='btnReset' value='Reset' />

            </td>
        </tr>
</table>
    </form>

My Result.php (in progress)

<?php error_reporting(E_ALL); ?>
<?php 
session_start();    // retrieve PHP session! 
header('Cache-Control: no-cache');
header('Pragma: no-cache');
if (!isset($_SESSION["name"]))
{
    header("Location: Calculator.php");
    exit( );
}
        if(!isset($_SESSION["pamount"]))
{
    $pamount = $_SESSION["pamount"];
}
if(!isset($_SESSION["irate"]))
{
    $irate = $_SESSION["irate"];
}
if(!isset($_SESSION["pamount"]))
{
    $y2d = $_SESSION["y2d"];
}
?> 
<html>
<head>
<title>Results</title>
<link rel = "stylesheet" type = "text/css" href = "style.css" />
</head>
<body>
<h3 class="distinct">Thank you <?php echo $_SESSION["name"]?>, for using out deposite calculation tool.</h3>
<p>Following is the results of calculation </p>
<form action='Result.php' method='post'>
<table>
                 <?php


                 $pamount = $_SESSION["pamount"];
                 $irate = $_SESSION["irate"];
                 $y2d = $_SESSION["y2d"];
                $runningPrincipal = $pamount;

                for($i = 1; $i <= $y2d; ++$i)
                {
                    $interest = $runningPrincipal * $irate * 0.01;

                    printf("<tr><td>%s</td><td>\$%.2f</td><td>\$%.2f</td></tr>", $i, $runningPrincipal, $interest);

                    $runningPrincipal += $interest;

                }
                ?>
                </table>
                </form>
<?php session_destroy();?>
</body>
</html>
  • 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-12T05:59:45+00:00Added an answer on June 12, 2026 at 5:59 am

    You need to do the validation on the same page, where the HTML form is given i.e. Calculator.php. On successful validation you will assign the entered values to session variables, and redirect to Result.php where you can do the calculation and display result.

    • 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 trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

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.