Jump to content

isset not working corrently


msebar
Go to solution Solved by Jacques1,

Recommended Posts

Sorry for the miss spell on correctly counldn't edit the title

 

I need to have the following 3 varibles checked to see if they are set and if not display an error saying "All fields need to be filled in."
My problem is that it's not working. Did I mess up on my if statement?

$tempneeded
$lowtemp
$gallons
 


<?php


$tempneeded = $_POST['tempneeded'];
$lowtemp = $_POST['lowtemp'];
$gallons = $_POST['gallons'];


     htmlspecialchars($tempneeded, ENT_QUOTES, 'UTF-8') . ' ' .  
     htmlspecialchars($lowtemp, ENT_QUOTES, 'UTF-8') . ' ' .  
     htmlspecialchars($gallons, ENT_QUOTES, 'UTF-8') . ' ' .  


$wgd = .5;
$tempdiff = $tempneeded - $lowtemp;
$wattsneeded = $tempdiff * ($gallons * $wgd);

if (!isset ($lowtemp,$tempneeded,$gallons))
{

echo "<b>All fields need to be filled in.</b>";

} else {
echo "<b>You will need a total of $wattsneeded watts to rasie your tempature $tempdiff degress, from $lowtemp to $tempneeded.</b></td></tr>";
}
?>



Edited by msebar
Link to comment
Share on other sites

Why don't you test them before you start manipulating them?

 

Actually - they will be "set" when you assign those POST vars to them, or else you would get an error/notice that the post vars are not set.  So what you really want to test is the POST vars for being set and for being <> blank

Edited by ginerjm
Link to comment
Share on other sites

The if statement doesn't work the rest of the code does. If I leave the fields blank coming in from the form it echo's the first statemnet. If I fill in the form the first statment still gets echoed and my results don't show. So my issue really is the else is not working

Link to comment
Share on other sites

  • Solution

An empty form field does have a value, namely the empty string. So the isset() check always succeeds unless you manually remove the form field so that the parameter isn't present at all. If you want to check for empty fields, you need the empty() statement. This covers both missing parameters and empty parameters.

  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.