I need to run php code when I click on btn.
my Html code:
<button type='button'>Run my PHP code</button>
my php code (run when click on btn) :
<?php
echo "Click On YesBtn";
?>
I need to run php code when I click on btn.
my Html code:
<button type='button'>Run my PHP code</button>
my php code (run when click on btn) :
<?php
echo "Click On YesBtn";
?>
If the button is in a .php page you can simply do:
<button type='button' onclick="document.write('<?php echo "Click On YesBtn"; ?>');>Run my PHP code</button>
if your php code is in a sepprate file you have to submit it with a GET/POST ect. request. Like so:
<form method="post" action="welcome.php" id="form1">
<button type="submit" form="form1" >Run my PHP code</button>
</form>
. . .
//welcome.php
<?php
echo "Click On YesBtn";
?>
The form has to have a type of "submit" in this case, then you can send the form data for processing to a PHP file of yours choice. The form data is sent with the HTTP POST OR GET method and also remember to set the form action. Below is a sample code.
<form method="post" action="welcome.php">
<input type="submit" name="submit">
</form>
//welcome.php
<?php
if(isset($_POST["submit"])){
echo "Click On YesBtn";
}
?>
You can make your button a submit button for a form that calls a php page https://www.w3schools.com/php/php_forms.asp