简体   繁体   English

单击“提交”按钮时传递两个值-PHP

[英]Pass Two values when a Submit button is clicked -PHP

This table is displaying details about my workload table per row. 该表每行显示有关我的工作量表的详细信息。 And when I click my "pre-View_attend" submit button I want to get the "WorkloadID" and "subjectID" of that workload row where the submit button was clicked. 当我单击“ pre-View_attend”提交按钮时,我想获得单击了提交按钮的工作负载行的“ WorkloadID”和“ subjectID”。

Currently I have a hidden field containing the subject ID which is "subjectID_hidden", and when I try to get the "WorkloadID" and "subjectID" by using isset. 当前,我有一个包含主题ID的隐藏字段,该主题ID为“ subjectID_hidden”,当我尝试使用isset来获取“ WorkloadID”和“ subjectID”时。

It seems that I can't accurately get the exact subject ID of the row where I've clicked the "pre-View_attend" submit button. 似乎我无法准确获得单击“ pre-View_attend”提交按钮的行的确切主题ID。

 <tbody style="font-size:20px; text-align:center;"> <tr> <td><?php echo $row["subjectName"]; ?></td> <td><?php echo $row["className"]; ?></td> <td><?php echo $row["RoomNumber"]; ?></td> <td><?php echo $Sched_Days.'<br>'.$FST.' To '.$FET;?></td> <td><button style="font-size:15px;" type="button" id="<?php echo $row["WorkloadID"]; ?>" class="btn btn-primary view_StudentList">View Student List</button></td> <td><button style="font-size:15px;" type="submit" name="gettingAttendance" value="<?php echo $row["WorkloadID"]; ?>" class="btn btn-primary">Take Attendance</button></td> <td><button style="font-size:15px;" type="submit" name="pre-View_attend" value="<?php echo $row["WorkloadID"]; ?>" class="btn btn-primary">View Attendance</button></td> <input type="hidden" name="subjectID_hidden" value="<?php echo $row["subjectID"]; ?>"> </tr> <?php } mysqli_close($connect);?> </tbody> /* I'm getting the workload ID accurately, but the subject ID is incorrect. I believe I'm getting the last subject ID that my query produced */ <?php if(isset($_POST['pre-View_attend'])) { $FWID=$_POST['pre-View_attend']; $FSJID=$_POST['subjectID_hidden']; echo"Workload ID: $FWID SubjectID: $FSJID"; } ?> 

You get the last value because you have a bunch of hidden fields with the same name. 获得最后一个值是因为您有一堆同名的隐藏字段。

You could name them subjectID_hidden[<?=$row['WorkloadID'];?>] to get an array to then get the subjectID by WorkloadID : 您可以将它们命名为subjectID_hidden[<?=$row['WorkloadID'];?>]以获取一个数组,然后通过WorkloadID获得subjectID

$subjectID = $_POST["subjectID_hidden"][$_POST["pre-View_attend"]];

You need to query the table for something unique to the row you want to retrieve information from. 您需要在表中查询要从中检索信息的行所特有的内容。 This unqiue data should already be existing on the page, encoded into the button/form. 页面上应该已经存在这种不正确的数据,已将其编码为按钮/表单。 Example; 例;

<?php
if(isset($_POST['pre-View_attend'])) {
global $db;
$select = "select * from mytable where unique='$unique'";
$connect = mysqli_query($db, $select);
while($row=mysqli_fetch_array($connect)) {
$myfirstVariable = $row['myfirstVariable'];
$mysecondVariable = $row['mysecondVariable'];
$show = "$myfirstVariable $mysecondVariable";
}
}
?>

Then you can call $show when you want in the HTML. 然后,您可以根据需要在HTML中调用$ show。 ps there are quite a few errors in your html like; PS在你的HTML像有很多错误;

<input type="hidden" name="subjectID_hidden" value="<?php echo $row["subjectID"]; ?>">

should be 应该

<input type="hidden" name="subjectID_hidden" value="<?php echo $row["subjectID"]; ?>" />

self closing at the end with forwards slash. 在结尾处以正斜杠自我关闭。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单击类型提交按钮时如何传递隐藏值? PHP - how to pass hidden value when type submit button is clicked? PHP 单击时是否可以通过1个单选按钮传递两(2)个值? - Is it possible to pass two (2) values from 1 radio button when clicked? 单击提交按钮时如何传递被单击按钮的值? - How pass a clicked button's value when submit button is clicked? 单击提交按钮时的PHP排序表 - PHP sort table when submit button is clicked 单击提交按钮时,PHP 会话结束 - PHP session ends when submit button is clicked 单击按钮提交后,如何将下拉列表中的选定值传递给url查询字符串? - How can I pass the selected values from the dropdown list to the url query string when button submit is clicked? 单击提交按钮时,将在javascript中创建的动态生成的html表保存并传递给php - preserve and pass dynamically generated html table created in javascript to php when submit button is clicked 使用一个提交按钮将值从一个php文件中的两个文本框传递到另一个php文件 - Pass values from TWO text boxes in a php file to another php file with a single submit button 在PHP中单击按钮时,值不更新或保存吗? - Values not updating or saving when button is clicked in PHP? 单击提交按钮时,php会话无法与表单一起使用 - php sessions doesn't work with form when submit button is clicked
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM