Jump to content

execute function inside another function


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">)

}

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.