Welcome Guest, Not a member yet? Register   Sign In
CI Problem with form validation
#3

(This post was last modified: 10-30-2014, 12:34 AM by Tim Brownlaw.)

An undefined variable error message, simply tells you that the variable you are trying to use is undefined!


You've done something like this

PHP Code:
if (something_that_might_happen === TRUE)
{
  
$message "Wow it worked"!
}

echo 
$message

So $message ONLY Exists - ie is defined if your IF statement is TRUE... When it's not, $message does not exist!


So you need to ensure that if you are going to use a variable anywhere, that it has to be SET to something!

PHP Code:
$message '';
if (
$something_that_might_happen === TRUE)
{
  
$message "Wow it worked"!
}
echo 
$message

or
PHP Code:
if ($something_that_might_happen === TRUE)
{
  
$message "Wow it worked!";
}
else
{
  
$message "Well that didn't work";
}
echo 
$message

And then you'd ask - Where does $something_that_might_happen get set?

PHP Code:
if (isset($something_that_might_happen) AND $something_that_might_happen === TRUE)
{
  
$message "Wow it worked!";
}
else
{
  
$message "Well that didn't work";
}
echo 
$message

And if you are using $_POST or _GET and any array and using those to test or display. Do they exist?

So really it's a matter of - "Oh I get an undefined variable or index or whatever.. Is it defined when it's being used?"

Hope that helps you fix your issue!
Reply


Messages In This Thread
CI Problem with form validation - by FlevasGR - 10-29-2014, 12:25 PM
RE: CI Problem with form validation - by ciadmin - 10-29-2014, 08:40 PM
RE: CI Problem with form validation - by FlevasGR - 10-30-2014, 04:33 AM
RE: CI Problem with form validation - by Narf - 10-31-2014, 11:49 AM
RE: CI Problem with form validation - by Tim Brownlaw - 10-29-2014, 11:30 PM
RE: CI Problem with form validation - by Avenirer - 10-30-2014, 05:56 AM
RE: CI Problem with form validation - by Avenirer - 10-30-2014, 06:12 AM



Theme © iAndrew 2016 - Forum software by © MyBB