Run php function on button click

JD_bravo

I want to run a php function on button click. for eg :

<input type="button" name="test" id="test" value="RUN"  onclick="<?php echo testfun(); ?>" /><br/>

<?php

function testfun()
{
   echo "Your test function on button click is working";
}

?>

My question is that when I do this I don't get the expected output I was looking for. Please give me the best solution for this to run a php function on button click whether it is a simple button or submit.

JD_bravo

I tried the code of William, Thanks brother.

but it's not working as a simple button I have to add form with method="post". Also I have to write submit instead of button.

here is my code below..

<form method="post">
    <input type="submit" name="test" id="test" value="RUN" /><br/>
</form>

<?php

function testfun()
{
   echo "Your test function on button click is working";
}

if(array_key_exists('test',$_POST)){
   testfun();
}

?>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

run a nested function on button click

How to run a function on button click?

Run PHP code with click on Button

incorrect run php by button click

Call php function on click of a button

Call PHP function on button click

Calling a PHP function on button click?

HTML on-click button to run javascript function

Javascript button click on event to run a function

Run a defined function on page load and on button click

How to intercept button click, run analytics code, and then continue with click function

How to call a PHP function on the click of a button

Using AJAX to call PHP function on button click

Button On click call jquery function and acess php

vuejs run function after click back button in browser

jQuery run same function on click button or onchange dropdown

Run JS function after form validates on button click

click a button multiple times to run the same function, java android studio

Function doesn't run when I click on the button

How to run Jquery function on modal popup button click

JQuery function - run on click and on page load for specific radio button

javascript run function only once per button click

How to run a function that a on form submit ajax with automatic click button

How to run a function declared in jsp from a button click

Run a function on custom button click in woocommerce admin order page

How do i run a node specific function on button click

Program to run through functions in a single button (1 function = 1 click)

How can calculate automatically without click any button to run function

Sending two forms after button click and run php in background