代码之家  ›  专栏  ›  技术社区  ›  Kuiu

使php识别是否单击了右键

  •  0
  • Kuiu  · 技术社区  · 6 年前

    我正在做一个简单的网站与个人资料,个人资料编辑等。我试图使它成为可能,这样一个人可以改变他们的偏好,如显示年龄等与个人资料编辑。因为我想为每一个可能的可更改的东西添加一个按钮,所以我需要添加多个提交按钮。这就是我的问题所在。我试过了 if($submitshowage) (isset($submitshowage)) ,但是由于我的第二个按钮不知道这个索引,它给了我 Notice: Undefined index: submitshowage in /storage/ssd4/637/3688637/public_html/profile/editprocess.php on line 16 错误。

    我的问题是如何让多个按钮工作,而不询问其他按钮只提供的信息。

    我的edit.php

    <form action="editprocess.php" method="POST">
    <input type="radio" name="showage" value="Yes" checked>
    <br>
    <input type="radio" name="showage" value="No">
    <br><br>
    <input type="submit" name="submitshowage" value="submit">
    </form>
    
    <form action="editprocess.php" method="POST">
    <p>Show your age publicly?</p>
    <input type="radio" name="showage" value="Yes" checked> Yes
    <br>
    <input type="radio" name="showage" value="No"> No
    <br><br>
    <input type="submit" name="submittest" value="submit">
    </form>
    

    我的editprocess.php

           <?php
    //Show age proberty
    $submitshowage = $_POST['submitshowage'];
    if($submitshowage) {
     if ($_POST['showage'] == 'Yes'){
         $answer = 1;
     } else {
         $answer = 0;
     }
        //id from cookie
        $id = $_COOKIE['id'];
    $sql = "UPDATE login SET showage='$answer' WHERE id='$id'";
    
        if ($conn->query($sql) === TRUE) {
        echo "Record updated successfully";
    } else {
        echo "Error updating record: " . $conn->error;
    }
    
        $conn->close();
    } else { }
        ?>
    

    所有可以变得更简单的事情(除非需要使用按钮)都无关紧要,因为这是我的第一个php项目,除了玩得开心,看看它能把我引向何方之外,我不打算用它做什么

    1 回复  |  直到 6 年前
        1
  •  0
  •   Nick SamSmith1986    6 年前

    更改此代码:

    $submitshowage = $_POST['submitshowage'];
    if($submitshowage) {
    

    致:

    if (isset($_POST['submitshowage']) {
    

    你也可以为其他提交按钮使用类似的代码。

    if (isset($_POST['submitshowemail']) {