I am trying to pass a variable to another page with url. I have several submit buttons inside my form. once I click on of them, all the other element names with their values are submitted along with the data of that specific submit button. Once I try to save it to the database, they last value is saved into the database, even if it is not the chosen one.

http://127.0.0.1/product-details.php?quantity=1&username=cabdiqani&time=1559032347&image=girl1.jpg&uprice=35&quantity=71&username=cabdiqani&time=1559032347&image=girl2.jpg&uprice=35&quantity=1&username=cabdiqani&time=1559032347&image=girl3.jpg&uprice=35

Only the last one is always saved. Even if the button I clicked is associated with the different quantity or unit price. I want to save only the data associated with the clicked button. Can someone help?

The code:

echo '<b class="btn btn-default get" style="color:black; border: 1px green solid; border-radius:15px;">Quantity:</b> 
      <input type=text name="quantity" class="btn btn-default get" value=1 style="width:10%; background-color: #aec45d;color:black;">
      <input type=submit class="btn btn-default get" value="Dalbo oo Hel">'; ?>

      <input type="hidden" name="username" value="<?php echo $_SESSION['logged']; ?>">
      <input type="hidden" name="time" value="<?php echo time(); ?>">
      <input type="hidden" name="image" value="<?php echo "girl1.jpg"; ?>">
      <input type="hidden" name="uprice" value="<?php echo 35; ?>">

1 Answers

0
Rahul Kumar Sharma On

Use

<form method="POST" action="submit.php"
   <input type=text name="quantity" class="btn btn-default get" value=1 style="width:10%; background-color: #aec45d;color:black;">
   <input type="hidden" name="username" value="<?php echo $_SESSION['logged']; ?>">
   <input type="hidden" name="time" value="<?php echo time(); ?>">
   <input type="hidden" name="image" value="<?php echo "girl1.jpg"; ?>">
   <input type="hidden" name="uprice" value="<?php echo 35; ?>">
   <input type=submit class="btn btn-default get" value="Dalbo oo Hel">
</form>