PHP和(isset($ _ POST ['']))问题

Jua*_*oux 5 php

抱歉,如果这个问题重复,我却没有找到一个明显的答案.我是一个完整的新手与,善良!当我加载以下代码时,if(isset($_POST['test']))即使我没有按下按钮,它似乎也会运行"test".我只想按下" test"按钮时执行代码.我该如何解决这个问题?

<?php
    if(isset($_POST['update'])) {
        $content=simplexml_load_file("books.xml");
        $value=$content->book->price;
        $sum=$content->book->price;
    }

    if(isset($_POST['test'])) {
        $content=simplexml_load_file("books.xml");
        $value=$content->book->price;
        $content->book->price = $value + 1.0;
        $content->asXML("books.xml");
        $sum=$content->book->price;
    }
?>

<body>
    <form method="post">
        <input type="checkbox" id="i1check1" onchange="toggleDisabled(this.checked)"> Alarm 01
        <input type="text" id="i1text1" name="i1" size="80" maxlength="128" value="<?php echo @$sum;?>"/>
        <input type="submit" id="i1btn1" name="update" value="Update"/>
        <input type="submit" id="i1btn2" name="test" value="Test"/>
    </form>

    <script>
        function toggleDisabled(_checked) {
            document.getElementById('i1text1').disabled = _checked ? false : true;
            document.getElementById('i1btn1').disabled = _checked ? false : true;
        }
    </script>
</body>
Run Code Online (Sandbox Code Playgroud)

Man*_*ani 5

请尝试一下

if(isset($_POST['update']) && $_POST['update'] == "Update"){
    $content=simplexml_load_file("books.xml");
    $value=$content->book->price;
    $sum=$content->book->price;
}

if(isset($_POST['test']) && $_POST['test'] == "Test"){
    $content=simplexml_load_file("books.xml");
    $value=$content->book->price;
    $content->book->price = $value + 1.0;
    $content->asXML("books.xml");
    $sum=$content->book->price;
}
Run Code Online (Sandbox Code Playgroud)