Jump to content

isset


westminster86

Recommended Posts

Try this!

<?php
   // check forms filled in
   if (!filled_out($_POST)) 
   {
      echo "You have not filled the form out correctly - please go back"
           ." and try again.";
      exit; 
   } 

function filled_out($form_vars)
{
  // test that each variable has a value
  foreach ($form_vars as $key => $value)
  {
     if (!isset($key) || ($value == "")) 
        return false;
  } 
  return true;
}
?>

Link to comment
Share on other sites

Uhhh, there's no way to do that. The only way to do that is if you store all your variable names into an array, then use a foreach to iterate through the array and check each one

 

There's no way for PHP to know what vars you want/don't want without telling it which ones are supposed to be there

Link to comment
Share on other sites

another good thing to do, would be to remove all spaces, and make sure that there are numeric and non-numeric values entered, because with empty, it looks to see if there is anything in the string, and a space does count so it will then return true.

 

isset only checks to see if a variable is set, not if the variable holds anything.

 

Example 1:

<?php
$cat = "";
isset($cat); // returns true
?>

 

Example 2:

<?php
$dog = "123121";
isset($dog); // returns true
?>

 

Example 3:

<?php
$dog = "123121";
isset($bird); // returns false
?>

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.