doupiai5597
doupiai5597
2017-06-20 19:01
浏览 45

按钮类型=使用php isset提交而不是输入类型按钮[复制]

This question already has an answer here:

I have been searching this stuff but could not find anywhere. when i search about button name and value, everywhere its mentioned about input type=button

But i am looking for button type=submit instead of input type=button i want to allow users to remove their comments. So, the delete button is just showing like a link

The Html is

<button class="likeslink" type="submit" name="delcom" value="<?php echo $comid ?>"><small>Delete</small></button>

I am not getting how can i check if this button is clicked or not not using php as i tried

<?php
if(isset('delcom'))
{
$sql = "DELETE FROM comments WHERE id = :id";
$stmt = $DB->prepare($sql);
$stmt->bindValue(":id", $comid);
$stmt->execute();
}
?>

But its not working.

Meanwhile, i want a popup alert message that confirms Delete Query includings Delete or Cancel buttons on it

I don't want that simple javascript alert on the top of the page. I want some popup window in the middle of the screen with my own Color scheme

Please help

</div>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanjie6912
    duanjie6912 2017-06-20 19:04
    已采纳

    Make sure to get it from the POST variable to check. This is probably what you're actually intending on doing.

    <?php
        if(isset($_POST['delcom']))
        {
            $sql = "DELETE FROM comments WHERE id = :id";
            $stmt = $DB->prepare($sql);
            $stmt->bindValue(":id", $comid);
            $stmt->execute();
        }
    ?>
    
    点赞 评论
  • doumu2172
    doumu2172 2017-06-20 19:07

    Basically, just create a simple form to go with your submit button, then use $_GET[] or $_POST[] to get the value:

    <form method="POST" action="path/to/php">
      <input type="hidden" name="dodelete" value="1" />
      <button type="submit">Delete</button>
    </form>
    

    And the PHP:

    if (isset($_POST['dodelete'])) {
      // do something
    }
    

    You could also just use a normal link:

    <a href="path/to/php?dodelete=1">Delete</a>
    

    and then just replace the $_POST with a $_GET in the PHP. You could also use a <button> instead of an anchor, but you'd have to add an onClick event to it.

    Also, just to let you know, the following sets are the same:

    • <input type="button" value="ABC" /> and <button tyoe="button">ABC</button>
    • <input type="submit" value="ABC" /> and <button type="submit">ABC</button>
    • <input type="reset" value="ABC" /> and <button type="reset">ABC</button>
    点赞 评论

相关推荐