arunpatal Posted November 26, 2013 Share Posted November 26, 2013 (edited) 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">) } Edited November 26, 2013 by arunpatal Quote Link to comment 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()); ?> Quote Link to comment Share on other sites More sharing options...
Solution arunpatal Posted November 26, 2013 Author Solution Share Posted November 26, 2013 (edited) 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 Edited November 26, 2013 by arunpatal Quote Link to comment 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.