【问题标题】:How to update database from Menu?如何从菜单更新数据库?
【发布时间】:2020-03-18 02:35:39
【问题描述】:
<div class="container">
    <h3 class="text-center">Hotel/Admin Joint Panel</h3>
    <table class="table table-bordered">
        <tr>
            <th>Food_ID</th>
            <th>Cuisines</th>
            <th >Description</th>
            <th >Price</th>
            <th >Image</th>
            <th >Date</th>
            <th width="50px">Action</th>
        </tr>

        <?php


          include_once 'mainclass.php';

          $confirmThread = new menuDatabase();

        $sql = "SELECT * FROM gallery";
        $users = mysqli_query($confirmThread->getCon(),$sql);


        while($user = $users->fetch_assoc()){


        ?>


            <tr  id="<?php echo $user['idGallery'] ?>" >
                <td ><?php echo $user['idGallery'] ?></td>
                <td><?php echo $user['titleGallery'] ?></td>
                <td><?php echo $user['descGallery'] ?></td>
                <td><?php echo $user['price'] ?></td>
                <!-- <td><?php echo ("data:image/jpeg;base64,".base64_encode($user['image'] )) ?></td> -->
                <td><?php echo '<img src="data:image/jpeg;base64,'.base64_encode($user['image'] ).'">'
             ?></td>
                <td width="100px"><?php echo $user['samaye'] ?></td>
                <td>

              <button  class="btn btn-danger btn-sm remove">Delete</button>
                  <button  style="margin-top: 2px" id="createOnly" class="btn btn-danger">  <a href="upload.php">Create Menu</a></button>
                  <button  style="margin-top: 2px" id="updateOnly" id="hi" class="btn btn-danger btn-sm  ">  <a class="update" href="upload.php">Update</a></button>
                </td>
            </tr>

              <?php } ?>








    </table>
</div> <!-- container / end -->

我想使用Menu.php 中的更新按钮更新数据库。我想要的是,当我单击更新按钮(在 menu.php 中)时,它应该获取 food_id(primary key) 并记住 Upload.php,从那里我通过获取所有新值进行真正的更新。

【问题讨论】:

  • 您想要实现的目标有很多东西。试一试,当您遇到问题时,我们很乐意再看一次。现在,这个问题太宽泛了,需要做一些工作。
  • 不知道怎么做,项目提交就在附近。????

标签: php ajax database


【解决方案1】:

你可以把下面的语句改成

<td>
   <button class = "btn btn-danger btn-sm remove">Delete</button>
   <button style = "margin-top: 2px" id = "createOnly" class = "btn btn-danger">  <a href = "upload.php">Create Menu</a></button>
   <button style = "margin-top: 2px" id = "updateOnly" id = "hi" class = "btn btn-danger btn-sm">  <a class = "update" href = "upload.php">Update</a></button>
</td>

这个。这将作为一个表单(仅适用于更新按钮),您可以将这些值发送到您的update.php。您需要的 id 已隐藏。从update.php 你可以做你需要做的事情。

<td>
   <button class = "btn btn-danger btn-sm remove">Delete</button>
   <button style = "margin-top: 2px" id = "createOnly" class = "btn btn-danger">  <a href = "upload.php">Create Menu</a></button>
   <form method = "post" action = "upload.php">
      <input type = "hidden" name="food_id" value="<?php echo $user['idGallery']; ?>"/>
      <button type = "submit" style = "margin-top: 2px" id = "updateOnly" id = "hi" class = "btn btn-danger btn-sm">Update</button>
   </form>
</td>

或者你可以像这样使用Query Parameter来做到这一点,

<td>
   <button class = "btn btn-danger btn-sm remove">Delete</button>
   <button style = "margin-top: 2px" id = "createOnly" class = "btn btn-danger">  <a href = "upload.php">Create Menu</a></button>
   <button style = "margin-top: 2px" id = "updateOnly" id = "hi" class = "btn btn-danger btn-sm">  <a class = "update" href = "upload.php?foodID=<?php echo $user['idGallery']; ?>">Update</a></button>
</td>

从你的update.php 你可以得到这样的结果,

$foodID = $_GET["foodID"];

希望对您有所帮助!

【讨论】:

  • 谢谢。如何解决它的非常彻底但简单的答案。我不只是想要一个“摆脱这个错误”的答案,我想理解它,这就是你为我所做的,谢谢。
  • facebook.com/arjun.bhat.14224094 是我的 Facebook 帐户。
  • 你能给我你的吗
  • 其实我没有用脸书。但如果您需要任何帮助,可以在这里发表评论。
  • 点击其他页面中的其他按钮后,$_GET['foodID'] 的值将丢失。我们如何为多个页面和多个目的存储 $_GET['any_value'] ?你有什么技巧吗?
猜你喜欢
  • 2015-05-20
  • 2017-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-30
  • 2015-03-24
  • 1970-01-01
相关资源
最近更新 更多