2017-05-20 20:11
浏览 67

HTML - 单击按钮时的PHP UPDATE数据库

I have html page that has several button. I want to update my database column when I click a button.

In index.html

<form action="db.php" method="post">
    <button type="submit" id="1_y" class="btn btn-success">1.Lambayı Yeşil Yak</button>
    <button type="submit" id="1_k" class="btn btn-danger">1.Lambayı Kırmızı Yak</button></form>

And it looks like that


My db table Webtek


What I want is to update 'birinci_lamba' to 1 when 1_y is clicked and update 'birinci_lamba' again to 0 when 1_k is clicked.

So, what should be my db.php page ? Or any other advise to do that ?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douluo1330
    douluo1330 2017-05-20 20:24

    You use a from-tag, so you should use <input.. instead of <button... You seem to use bootstrap and <input class="btn btn-danger" /> should also work.

    Then, you need to give your inputs a name attribute:

    <form action="db.php" method="post">
    <input type="submit" name="1_y" id="1_y" class="btn btn-success">1.Lambayı Yeşil Yak />
    <input type="submit" name="1_k" id="1_k" class="btn btn-danger">1.Lambayı Kırmızı Yak /></form>

    Your db.php file could look like that:

      mysql_query("..."); //your update-query
    } elseif(isset($_POST['1_y']){
      mysql_query("..."); //your other update-query
    点赞 评论