Jacques58 Posted June 22, 2017 Share Posted June 22, 2017 Good day, I am creating a WebAPP with HTML, PHP and MySQL. I am new to PHP and to this forum, I tried to search for a related topic but I could not find one. The part I'm struggling with is, when creating a table listing all my products from my database, I need a button to be created with it, so that when I click on that button, the item connected to this button gets added into a separate table in the database. Any help or guidance would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted June 22, 2017 Share Posted June 22, 2017 You aren't going to get much help if all you provide is a vague story about what you want to do.Show the concrete code (in code tags). Show what you've tried and what exactly you're struggling with. If you haven't tried anything yet, do it now. Quote Link to comment Share on other sites More sharing options...
Jacques58 Posted June 22, 2017 Author Share Posted June 22, 2017 Hi, Thank you and noted. Below is the part where I get stuck. On clicking of the button, how can I pass the variable '$row[prodCode]' to another php script, to use this variable? <?phprequire('dbconnect.php');$ri = "SELECT prodDesc, prodPrice, prodCode FROM products";$result = mysqli_query($con, $ri);if ($result->num_rows > 0) { echo "<p>Sample</p>"; echo "<table border=1px><tr><th>Item</th><th>Price</th></tr>"; while ($row = $result-> fetch_assoc()) { echo "<tr><td width='100' align='center'>".$row["prodDesc"]. "</td><td width='100' align='center'>".$row["prodPrice"]. "</td><td>". "<button id='use' type='button' value='$row[prodCode]' >Use</button>". "</td></tr>"; } echo "</table>";} else { echo "0 results";}mysqli_close($con);?> Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted June 22, 2017 Share Posted June 22, 2017 A <button> by itself doesn't do anything. What you need is a form which contains the data you want to send as well as a submit button to trigger form submission. Forms are a basic HTML feature, and there are thousands of tutorials explaining them in great detail (like this one). To set input data without user interaction, you use a hidden field. Quote Link to comment Share on other sites More sharing options...
Jacques58 Posted June 22, 2017 Author Share Posted June 22, 2017 Thank you, appreciate you pointing me in the right direction! Quote Link to comment Share on other sites More sharing options...
Jacques58 Posted June 22, 2017 Author Share Posted June 22, 2017 Wow, works exactly like what I had in mind when I used forms. Thanks again!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.