php - Use a button to pass data to a database -


i don't know if valid question site, but...

i'm wondering how can use buttons add data database without use of forms? have table of "products" , want click button beside each product information add item orderlist in database. (user cart purchases)

so assign value button when it's clicked match unique product_id in databse , know product being selected. if click each button mimick user adding product cart.

i have 9 products in database (don't mind 1)... want click button generate action populate table within db.

thanks

    <pre> <b>id   description         stock left  price   order id</b> </pre>     <table align="left" border="1px" cellpadding="10" cellspacing="18" style="width: 450px;">   <?php $servername = "localhost"; $username = "inserter"; $password = "123456"; $dbname = "pc_master_race";  // create connection $conn = new mysqli($servername, $username, $password, $dbname); // check connection if ($conn->connect_error) {      die("connection failed: " . $conn->connect_error); }   $sql = "select product_id, product_name, current_stock, product_price stock"; $result = $conn->query($sql);  if ($result->num_rows > 0) {      // output data of each row      while($row = $result->fetch_assoc()) {       echo "<tr><td>". $row["product_id"] . "</td><td>". $row["product_name"] . "</td><td>". $row["current_stock"] . "</td><td>". $row["product_price"] . "</td></tr>";      } } else  {      echo "0 results"; }  $conn->close(); ?> </table>  <br> <input value="order 1" type="submit"><br> <br> <input value="order 1" type="submit"><br> <br> <input value="order 2" type="submit"><br> <br> <input value="order 3" type="submit"><br> <br> <input value="order 4" type="submit"><br> <br> <input value="order 5" type="submit"><br> <br> <input value="order 6" type="submit"><br> <br> <input value="order 7" type="submit"><br> <br> <input value="order 8" type="submit"><br> <br> <input value="order 9" type="submit"><br> 

browse page

i wrap each of items such own form. way can post data specific order.

<table align="left" border="1px" cellpadding="10" cellspacing="18" style="width: 450px;"> <thead>   <tr><th>id</th><th>description</th><th>stock left</th></th>price</th><th>order id</th></tr> </thead> <tbody> <?php $servername = "localhost"; $username = "inserter"; $password = "123456"; $dbname = "pc_master_race";  // create connection $conn = new mysqli($servername, $username, $password, $dbname); // check connection if ($conn->connect_error) {      die("connection failed: " . $conn->connect_error); }   $sql = "select product_id, product_name, current_stock, product_price stock"; $result = $conn->query($sql);  if ($result->num_rows > 0) {      // output data of each row      while($row = $result->fetch_assoc()) {         echo "<tr><td>{$row['product_id']}</td><td>{$row['product_name']}</td><td>{$row['current_stock']}</td><td>{$row['product_price']}</td><td><form action="placeorder.php" method="post"><input type='hidden' name='order_id' value='{$row['product_id']}'><button type='submit'>order {$row['product_id']}</button></form></td></tr>";      } } else {    echo "0 results"; }  $conn->close(); ?> </tbody> </table> 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -