Imad Posted July 10, 2008 Share Posted July 10, 2008 Hi guys, when I try to submit form data to a database while all the code being in a function, I get a MySQL error. However, if the code isn't in a function it works. Do I need to add something for it to work within a function? Best Regards. Link to comment https://forums.phpfreaks.com/topic/114166-solved-php-function-wont-work/ Share on other sites More sharing options...
trq Posted July 10, 2008 Share Posted July 10, 2008 Its likely a scope issue or something, can we see some code? Link to comment https://forums.phpfreaks.com/topic/114166-solved-php-function-wont-work/#findComment-587006 Share on other sites More sharing options...
PFMaBiSmAd Posted July 10, 2008 Share Posted July 10, 2008 Variables used inside functions are local to that function. This is so that you can write a function to do anything it needs, but it won't interact with the main program (functions call be called any number of times and they can be reused in other pieces of code.) You need to pass values into functions as parameters in the function call. Link to comment https://forums.phpfreaks.com/topic/114166-solved-php-function-wont-work/#findComment-587007 Share on other sites More sharing options...
Imad Posted July 10, 2008 Author Share Posted July 10, 2008 @ PFMaBiSmAd: That one line of code you have in your sig is the best suggestion. I fixed my problem; Thanks for everyone's replies. Link to comment https://forums.phpfreaks.com/topic/114166-solved-php-function-wont-work/#findComment-587019 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.