Welcome Guest, Not a member yet? Register   Sign In
Non CI - PHP5 undefined variables
#1

[eluser]nevsie[/eluser]
Please forgive the non direct CI question... but i have a non programmers question on a difference between php5 and php4...

Previously i used to have a basic sendmail form... Nothing clever, but it worked... I used to put in the value field in short tags:
Code:
<?=$_POST['inputvalue']?>

(please ignore the obvious security risks, i take other precautions... This about something else!)

In PHP4 if this value was empty, nothing would display... If full from a form post it would leave content i want in there (in case the user missed or required field or similar).

However, in PHP5 this is now being flagged as "undefined variable"... Which yes i agree it is...

Now my main question really is... Is this a warning message setting that the host previously suppressed. Or is this something in PHP5 to make people do things correctly? And if so... What should i be doing here? I cannot believe i have to enter a longer line of if isset echo... etc...

Any advice or explanations appreciated... As i say only really learning and playing here and want to make sure i learn things correctly!!
Cheers, N
#2

[eluser]Pascal Kriete[/eluser]
Sounds like a configuration difference. A different error reporting level, or maybe register_globals was turned on for the php4 setup.

The easiest way to solve it is to check if it's set:
Code:
<?= isset($_POST['inputvalue']) ? $_POST['inputvalue'] : '' ?>

Or if you're using CI you can just use the input library, which will do that check for you:
Code:
<?=$this->input->post('inputvalue');?>
#3

[eluser]nevsie[/eluser]
hi thanks for the reply... i am not sure if it was register_globals as it is not what i am trapping really... But yes i suspect your right on error reporting...

that isset statement is significantly shorter, thank my if isset echo, but still seems crazy long compared to just raw output... but i guess raw output is bad!!!
Thanks for the response though.




Theme © iAndrew 2016 - Forum software by © MyBB