Click here to Skip to main content
15,897,718 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i've trying of the next way

PHP
 <?php  <br mode="hold" /?> function myfnc()
{   
echo "Hello world" ;   
}  
?>  
<form action="trytocallfunction.php" method="post">
<input type="submit" name="submit" value="submit"  önclick="<?php myfnc();??>" />
</form>
Posted
Updated 7-May-20 13:59pm
v2
Comments
Mohibur Rashid 28-May-14 22:36pm    
This is not how server works, this is not how php works. This is a very common mistake by newbie and very common question on line.

Try to understand how ajax work and find a way to fit ajax in your requirements.
Peter Leow 28-May-14 23:06pm    
ajax may be too far fetch for OP who has not got the correct understanding of how the web works.

1 solution

The myfnc() exists on the server-side and is to be executed on the server-side only, it will not appear on the client-side, you have to submit the form to the server and call the function over there, try this:
XML
<?php
if (isset($_POST['submit']))
{
   myfnc();
}
function myfnc()
{
    echo "Hello world" ;
}
?>
<form action="trytocallfunction.php" method="post">
<input type="submit" name="submit" value="submit">
</form>

You should read this to find out more Beginner's Guide to HTML5 & CSS3 - Server Side Story[^]
 
Share this answer
 
Comments
Mohibur Rashid 29-May-14 1:06am    
this is one way to go........

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900