问题描述
我在PHP中的新秀刚开始学习这门语言的基础知识。
I am a rookie in PHP and have just started learning the basics of this language.
我创建了一个名为页的functioncalling.php包含两个按钮,提交并插入。作为PHP初学者,我想测试一个按钮被点击时,执行该功能。我希望输出来在同一页上。所以,我创建了两个功能,一是为每个按钮。该人士$ C $ C为functioncalling.php如下:
I have created a page called functioncalling.php that contains two buttons, Submit and Insert. As a beginner in PHP, I want to test which function is executed when a button gets clicked. I want the output to come on the same page. So I created two functions, one for each button. The source code for functioncalling.php is as follows:
<html>
<body>
<form action="functioncalling.php">
<input type="text" name="txt" />
<input type="submit" name="insert" value="insert" onclick="insert()" />
<input type="submit" name="select" value="select" onclick="select()" />
</form>
<?php
function select(){
echo "The select function is called.";
}
function insert(){
echo "The insert function is called.";
}
?>
这里的问题是,我没有得到任何输出任何按钮被点击后。
The problem here is that I don't get any output after any of the buttons are clicked.
谁能告诉我究竟哪里我要去错了吗?在最早的答复将是非常美联社preciated。谢谢你在前进。
Can anyone please tell me where exactly am I going wrong? Replies at the earliest will be highly appreciated. Thank you in advance.
推荐答案
按钮点击是客户端
wheras PHP是服务器端
,但您可以使用此achive AJAX
Button click is client side
wheras PHP is server side
, but you can achive this by using ajax
$('.button').click(function() {
$.ajax({
type: "POST",
url: "some.php",
data: { name: "John" }
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});
});
在你的PHP文件:
<?php
function abc($name){
//your code here
}
?>
这篇关于如何调用PHP函数上点击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!