arunpatal Posted November 26, 2013 Share Posted November 26, 2013 can i execute function within a function ??? For example function a ($form) { echo "<div> $form </div>"; } function b() { insert into database statement..... echo "data inserted"; } if (isset $_POST["name"]) { a ( b() ) } else { a (<input type="text" name="name">) } Link to comment https://forums.phpfreaks.com/topic/284299-execute-function-inside-another-function/ Share on other sites More sharing options...
Barand Posted November 26, 2013 Share Posted November 26, 2013 Not as you have there. function a() expects a form as its parameter therefore b() would need to return a form. b() is not returning anything. Also, write your functions to return a result rather than echo something. This would work <?php function a($form ) { return "<div>$form</div>"; } function b() { $formElements = "<form>\n"; $formElements .= "<input type='text' name='name' />\n"; $formElements .= "<input type='submit' name='btnSubmit' value='Submit' />\n"; $formElements .= "</form>\n"; return $formElements; } echo a(b()); ?> Link to comment https://forums.phpfreaks.com/topic/284299-execute-function-inside-another-function/#findComment-1460185 Share on other sites More sharing options...
arunpatal Posted November 26, 2013 Author Share Posted November 26, 2013 everything is working just fine the way i did.......... but the only problem is that the message DATA INSERTED dose not show inside the div...... Its showing DATA INSERTED message above the div (div which is in function a) OK.... Its working now........ function b should return the value but not echo...... function b() { insert into database statement..... return "data inserted"; Thanks Barand Link to comment https://forums.phpfreaks.com/topic/284299-execute-function-inside-another-function/#findComment-1460186 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.