Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
影响函数的按钮-PHP_Php_Function_Button - Fatal编程技术网

影响函数的按钮-PHP

影响函数的按钮-PHP,php,function,button,Php,Function,Button,情景: 我试图让我的页面的一部分持续运行一个函数,当单击上面的按钮时,该函数就会受到影响。 按钮调用主/常量功能内的功能;硕士(已选定) 这是我试过的。 index.php: <? session_start(); require("inc.ini.php"); ?> <!doctype html> <html> <head> <link rel="stylesheet" type="text/css" href="styles.css"&

情景: 我试图让我的页面的一部分持续运行一个函数,当单击上面的按钮时,该函数就会受到影响。 按钮调用主/常量功能内的功能;硕士(已选定)

这是我试过的。 index.php:

<? session_start();
require("inc.ini.php");

?>
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
<meta charset="utf-8">
<title>Buttons to funtions</title>
</head>

<body>
    <main>
        <header>
                <form method="post"  action="<?=$_SERVER['php_self']?>">
                    <button type="submit" name="change" value="insert, <?$selected = "func1";?>">Func 1</button>
                    <button type="submit" name="change" value="insert, <?$selected = "func2";?>">Func 2</button>
                </form>
        <!--
        I want to press a button and when it is pressed it calls the function selected and gives it the value of which the button represents.
        -->
        </header>
        <figure>
            <?
            if($_POST['change']){
                echo $selected;
                master($selected);
            }
            ?>
        </figure>
    </main>
</body>
</html>

功能按钮

Php是一种服务器端语言,这意味着需要向服务器发送请求以使代码运行

此外,当表单提交时,它的所有子项都会被发送,因此无法区分单击了哪个

也就是说:

<?php
    session_start();
    require("inc.ini.php");
?>
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
<meta charset="utf-8">
<title>Buttons to funtions</title>
</head>

<body>
    <main>
        <header>
                <form method="post"  action="<?=$_SERVER['php_self']?>">
                    <button type="submit" name="change" value="Func1">Func 1</button>
                </form>
                <form method="post"  action="<?=$_SERVER['php_self']?>">
                    <button type="submit" name="change" value="Func2">Func 2</button>
                </form>
        </header>
        <figure>
            <?php
                if (isset($_POST['change'])) {
                    echo $_POST['change'];
                    master($_POST['change']);
                }
            ?>
        </figure>
    </main>
</body>
</html>

功能按钮

你需要javascript和ajax,或者重命名提交按钮。好的,你对我想做的事有什么建议?基本上,我正在制作一个学习PHP的网站,它是基于将我创建的游戏库加载到一个页面中的。这段代码的实际结果是什么?你想让它做什么?我只想制作一个新游戏(通过按钮选择的游戏)加载到一个图形中
<?php
    session_start();
    require("inc.ini.php");
?>
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
<meta charset="utf-8">
<title>Buttons to funtions</title>
</head>

<body>
    <main>
        <header>
                <form method="post"  action="<?=$_SERVER['php_self']?>">
                    <button type="submit" name="change" value="Func1">Func 1</button>
                </form>
                <form method="post"  action="<?=$_SERVER['php_self']?>">
                    <button type="submit" name="change" value="Func2">Func 2</button>
                </form>
        </header>
        <figure>
            <?php
                if (isset($_POST['change'])) {
                    echo $_POST['change'];
                    master($_POST['change']);
                }
            ?>
        </figure>
    </main>
</body>
</html>