-2
<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 -->

I wanted to update the database using an update button which is in Menu.php. What I wanted is, when I clicked on the update button(in menu.php) it should grab the food_id(primary key) and remember this for Upload.php, from where I am doing real updating by getting all new values.

Image

Hasitha Jayawardana
  • 2,326
  • 4
  • 18
  • 36
Arjun Bhat
  • 15
  • 5
  • There's a lot of stuff out there for what you want to achieve. Give it a try and when you had trouble with something, we'll be glad to take (another) look. Right now, the question is too broad and will require a bit of work. – Funk Forty Niner Nov 22 '19 at 03:57
  • I don't know how do i make this work, and project submission is nearby. – Arjun Bhat Nov 22 '19 at 04:26

1 Answers1

0

You can change the following statement to

<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>

this. This will act as a form (Only for the update button) and you can get these values to your update.php. The id that you need is hidden. From update.php you can do what you need to.

<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>

Or else you can do this by using Query Parameter like this,

<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>

and from your update.php you can get the result like this,

$foodID = $_GET["foodID"];

Hope this helps you!

Hasitha Jayawardana
  • 2,326
  • 4
  • 18
  • 36
  • Thank you. Very thorough but simple answer for how to solve it. I didn't just want a "just get rid of this error" answer, I wanted to understand it and that is what you did for me, Thank you. – Arjun Bhat Nov 22 '19 at 07:10
  • https://www.facebook.com/arjun.bhat.14224094 is my fb account. – Arjun Bhat Nov 22 '19 at 07:22
  • Can you give me yours – Arjun Bhat Nov 22 '19 at 07:22
  • Actually I am not using facebook. But you can comment here if you need any help. – Hasitha Jayawardana Nov 22 '19 at 11:29
  • That value of $_GET['foodID'] will be lost after clicking other buttons in another page. How can we store $_GET['any_value'] for multiple page and multiple purposes? Do you have some tricks? – Arjun Bhat Nov 23 '19 at 13:32
  • Once you get the `foodID` you can fetch data from the database or can do whatever you need on that particular page. But if you need to pass that value to another page you can use the Query Parameter again. If not you can use `session` or `cookies`. [Here](https://stackoverflow.com/questions/871858/php-pass-variable-to-next-page), [here](https://stackoverflow.com/questions/25927718/php-how-to-send-values-in-multiple-pages-form) are some examples. – Hasitha Jayawardana Nov 23 '19 at 17:58