我的问题是,当我这样做时,我没有得到我正在寻找的预期输出。请给我最好的解决方案,以便在单击按钮时运行 php 函数,无论它是简单的 butt-6ren">
gpt4 book ai didi

php - 单击按钮运行 php 函数

转载 作者:可可西里 更新时间:2023-11-01 12:30:12 24 4
gpt4 key购买 nike

我想在单击按钮时运行一个 php 函数。例如:

<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";
}

?>

我的问题是,当我这样做时,我没有得到我正在寻找的预期输出。请给我最好的解决方案,以便在单击按钮时运行 php 函数,无论它是简单的 button 还是 submit

最佳答案

William的代码试过了,谢谢大哥

但它不是一个简单的按钮,我必须添加带有 method="post"的表单。我也必须写提交而不是按钮。

下面是我的代码..

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

?>

关于php - 单击按钮运行 php 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32824360/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com