kenyi Posted January 12, 2007 Share Posted January 12, 2007 [code]function f_ret_error($element) { if ($error[$element] == 1) { echo $return_error[$element];}}function f_err_mem($element) { if ($error[$element] == 0){ echo $profile[$element];} else { echo $_POST[$element];} }<input name='phone' type='text' maxlength="15" value="<? f_err_mem("phone"); ?>"><? f_ret_error('phone');?>[/code]the code above works when they are not declared as function. Link to comment https://forums.phpfreaks.com/topic/33867-helpfunction-doesnt-work/ Share on other sites More sharing options...
Accipiter Posted January 12, 2007 Share Posted January 12, 2007 You can't use a variable in a function if it is declared outside of it.If you wish to use one, you have to set it as global, like this:[code]function f_ret_error($element) { global $error, $return_error; // This will tell PHP that $return_error declared outside the function should be used inside too if ($error[$element] == 1) { echo $return_error[$element];}}function f_err_mem($element) { global $error, $profile; if ($error[$element] == 0){ echo $profile[$element];} else { echo $_POST[$element];} }[/code]Observe that $_POST ($_GET, $_FILES etc) are already global variables, so called Superglobals.Good luck with further coding! :) Link to comment https://forums.phpfreaks.com/topic/33867-helpfunction-doesnt-work/#findComment-158927 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.