klepec Posted March 27, 2012 Share Posted March 27, 2012 I have a code where i include file (on submit). if isset(... include "example.php"; This example.php contains a variable $message which i later print in original code. How do i prevent getting undefined variable errors? (before submit button is pressed) Thanks Quote Link to comment https://forums.phpfreaks.com/topic/259798-include-problem/ Share on other sites More sharing options...
cpd Posted March 27, 2012 Share Posted March 27, 2012 Apply an "isset()" to where-ever your using the variable but it could be argued, and I would argue, that's bad execution practice. <?=(isset($message) ? $message : "");?> Quote Link to comment https://forums.phpfreaks.com/topic/259798-include-problem/#findComment-1331508 Share on other sites More sharing options...
mr.noname Posted March 27, 2012 Share Posted March 27, 2012 you can use the default value for example $message = "you default value"; include("some_process_file_that_change_behavior_of_message_var.php"); //follow you code check here hope it help Quote Link to comment https://forums.phpfreaks.com/topic/259798-include-problem/#findComment-1331512 Share on other sites More sharing options...
cpd Posted March 27, 2012 Share Posted March 27, 2012 you can use the default value for example $message = "you default value"; include("some_process_file_that_change_behavior_of_message_var.php"); //follow you code check here It's another option but then your blinded as to what's happening to $message. Its only a work around not a practical solution in my opinion. hope it help Quote Link to comment https://forums.phpfreaks.com/topic/259798-include-problem/#findComment-1331515 Share on other sites More sharing options...
klepec Posted March 27, 2012 Author Share Posted March 27, 2012 ...but it could be argued, and I would argue, that's bad execution practice. What do you mean by that? Can you please suggest a better way of doing this? Thanks for the answers Quote Link to comment https://forums.phpfreaks.com/topic/259798-include-problem/#findComment-1331535 Share on other sites More sharing options...
cpd Posted March 27, 2012 Share Posted March 27, 2012 It means you could ultimately end up testing every single variable just because you want to print it out. What is your specific example and I may be able to suggest an alternative method? Quote Link to comment https://forums.phpfreaks.com/topic/259798-include-problem/#findComment-1331537 Share on other sites More sharing options...
klepec Posted March 27, 2012 Author Share Posted March 27, 2012 I know :/ ... i do includes whenever i operate with the databases and forms. For example, there is a user form for storing company information and few company images. In original file i usually do the html (form), and submit button isset condition (PHP). In included file (PHP only) i operate with post variables, create thumbnails, save images, insert to database, select from database.... etc Then back in original file I usually print out database results, messages etc. Quote Link to comment https://forums.phpfreaks.com/topic/259798-include-problem/#findComment-1331539 Share on other sites More sharing options...
cpd Posted March 27, 2012 Share Posted March 27, 2012 If the include file is directly related to the file your executing then just put the code in the same php file as your html file. There's not really any need to create another page for it. Quote Link to comment https://forums.phpfreaks.com/topic/259798-include-problem/#findComment-1331545 Share on other sites More sharing options...
klepec Posted March 27, 2012 Author Share Posted March 27, 2012 Okay, ill do that. Thanks for all the help ) Quote Link to comment https://forums.phpfreaks.com/topic/259798-include-problem/#findComment-1331547 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.