简体   繁体   English

如何查看php中已按下哪个按钮?

[英]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.

相关问题 如何检查PHP中按下了哪个输入按钮? - How do I check which input button has been pressed in PHP? 如何确定通过PHP按下的提交按钮 - How can I determine which submit button that is pressed through PHP 仅在按下“发送表单”按钮后,如何调用PHP表单字段验证? - How to invoke PHP form fields validation only after the “send form” button has been pressed? 我可以在按下表单中的提交按钮后设置 cookie 吗? - Can I set a cookie after a submit button in a form has been pressed? 如何在按下提交按钮后运行我的 testxml.php 文件? - How to get my testxml.php file to run after the submit button has been pressed? 如何检测按下了哪个提交按钮? - How can I detect which submit button was pressed? 我如何用php显示哪些图像已经在输入类型文件中上传? - How I can show which image has been uploaded inside input type file with php? 如何检查在PHP中按下哪个按钮 - how to check which button pressed in php 如何检测使用PHP打开的邮件是否已打开,在哪个浏览器(用户代理)和OS中打开? - How can i detect if the mail which i sent has been opened, and in which browser (user agent), and OS using PHP? 如何在view2.gnp中的view1.php中定义的view2.php中使用PHP变量? - How can I use a PHP variable in view2.php which has been defined in view1.php in CodeIgniter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM