Jump to content

execute function inside another function


Go to solution Solved by arunpatal,

Recommended Posts

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 by arunpatal

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());
?>
  • Solution

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 by arunpatal
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.