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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:33:52+00:00 2026-06-14T04:33:52+00:00

FINAL EDIT (RESOLVED) I just replaced if(empty($num1)) with if(!isset($num1)) and now the conditional Required!

  • 0

FINAL EDIT (RESOLVED)

I just replaced if(empty($num1)) with if(!isset($num1)) and now the conditional Required! notice works flawlessly. Big thanks to everyone involved, I regained some already lost powers and I’m starting to finally make it into a fully functional, styled widget 😀 have a good day/night!

EDIT:

I have foolishly assumed that isset() is only for checkboxes…
I got rid of the Notice: Undefined index, yet the problem with Required! persists…


I have the following problem, I’ve made a calculator for product pricing, but if I load it for the first time it doesn’t “recognize” the null value in not-yet-filled-in text inputs… I’m not sure if I’m naming it right, I’m such a greenhorn when it comes to PHP, just started learning…

The form works flawlessly in general, I just want to get rid of this small problem.

Basically, I have following code:

$num1 = (int)$_POST['number1'];
$num2 = (int)$_POST['number2'];
$ratio = 0.2;
$utw = 1;

if (! empty($num1) && ! empty($num2)) {

    if ($num1 * $num2 <= 200) {
        $ratio = 0.2;
    }
    elseif ($num1 * $num2 > 200 && $num1 * $num2 < 400) {
        $ratio = 0.15;
    }
    elseif ($num1 * $num2 >= 400) {
        $ratio = 0.1;
    }

    if (isset($_POST['condition'])) {
        $utw = 1.8;
    }

    $price = $num1 * $num2 * $ratio * $utw;

}
else {
    $price = 0;
}

and

<form method="post" action="">

        <label for="number1">
            <input type="text" name="number1" id="number1">
            <?php if(empty($num1)) : ?><span style="color: red;">Required!</span><?php endif; ?>
            <br />Label1
        </label>

        <label for="number2">
            <br /><input type="text" name="number2" id="number2">
            <?php if(empty($num2)) : ?><span style="color: red;">Required!</span><?php endif; ?>
            <br />Label2
        </label>

        <label for="condition">
            <br /><input type="checkbox" name="condition" name="condition">
            Label3<br />
        </label>

        <input type="submit" value="Run">   

        <?php if($price > 0) : ?>
        <p><?php echo "Price equals: $price"; ?></p>
        <?php endif; ?>
</form>

When I display it for the first time I get the

Notice: Undefined index: number1 in C:\wamp\www\calc\index.php on line 3

(line 3 because of the fact that I stripped <!doctype html> and <?php obviously)

How to avoid it? Additionally, how to ensure that the Required! notice appears only if the user clicks the submit button? Currently it is displayed since the beginning because of the fact that input fields are empty… I don’t want them “empty” I just want them, you know… visually empty or equal to 0…

I’ve worked on all of this for several hours now, have found some solutions for that PHP debug notice, but it mainly involves if (isset($var)) method, assuming I have a checkbox… Well, I don’t… The other method with default $_POST values was to actually replace

$num1 = (int)$_POST['number1'];

with:

if ($_POST['number1'] == '') { 
$num1 = '0'; 
else { 
$num1 = $_POST['number1'] ; 
}

well, the notice still appears 🙁

Can anyone help me, please?

  • 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-14T04:33:54+00:00Added an answer on June 14, 2026 at 4:33 am

    I believe isset is actually what you want; it’s irrelevant what kind of input you are using. You could write a helper function like:

    function getPost($key, $default) {
        if (isset($_POST[$key]))
            return $_POST[$key];
        return $default;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

FINAL EDIT: After following the answer from Darin Dimitrov, I have found that the
Final Edit: I was able to locate the duplicate field in the ini file.
Final edit: Result using matplot() I'll see to it that I work with ~3
read final edit for solution I'm try update the onclick function of a link
Final EDIT working code (Huge thanks to Claus for taking time and solving it):
FINAL EDIT (Partial Solution): After a lot of tinkering I've been able to accomplish
FINAL EDIT: This turned out to be a stack overflow problem related to neither
Final goal: Have a few java objects sharing the same base class persisted into
final String message[] = {,,}; try{ String UID = null, UBAL = null; DateFormat
private final List<KeyListener> keyListeners= new CopyOnWriteArrayList<KeyListener>(); public void addKeyListener(KeyListener keyListener){ keyListeners.add(keyListener); } In the

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.