[英]How can I see which button has been pressed in php?
I'm quite new to php so this might seem very easy. 我对php很陌生,所以这似乎很容易。 I have a table called 'products' and for each product in that table I want to create a button with the id of that product.
我有一个名为“产品”的表,对于该表中的每个产品,我想创建一个带有该产品ID的按钮。 I have no problem creating the buttons but I can not see which of the buttons has been pressed.
创建按钮没有问题,但是看不到已按下哪个按钮。
How can I solve this? 我该如何解决?
This is my code: 这是我的代码:
$sql = "SELECT id FROM `products` WHERE subcategory = 'laptop' ORDER BY id desc limit 1";
$query = mysql_query($sql);
$id = mysql_result($query,0);
for($i=1; $i<= $id; $i++){
$product2 = R::load('products', $i);
echo "<input type='submit' name='$product2->id' value='Add to cart'/>";
}
Thank you ! 谢谢 !
assign a value to the button/input 为按钮/输入分配值
<input type="submit" name="btn" value="button1" />
<input type="submit" name="btn" value="button2" />
<input type="submit" name="btn" value="button3" />
<?php echo filter_input(INPUT_POST, 'btn'); ?>
or 要么
<input type="submit" name="btn1" value="button1" />
<input type="submit" name="btn2" value="button2" />
<input type="submit" name="btn3" value="button3" />
<?php if (filter_has_var(INPUT_POST, 'btn1')) { echo "button 1 clicked"; } ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.