【发布时间】:2016-05-08 10:36:32
【问题描述】:
我在这个论坛上找不到我的问题的解决方案。我试图通过从我的数据库中提取数据来为提交按钮提供一个 PHP 值(唯一 ID)。我还想将值存储在 SESSION 中。当我将字符串以外的值作为值时,提交按钮不起作用。 学生观:
<pre>
<?php foreach ($tabinternships as $internship) { ?>
<tr>
<td><span class="html"><?php echo $internship->id_internship() ?></span></td>
<td><?php echo $internship->email_teacher1_internship() ?></span></td>
<td><?php echo $internship->email_teacher2_internship() ?></span></td>
<td><?php echo $internship->email_responsible_internship() ?></span></td>
<td><?php echo $internship->id_promoter_internship() ?></span></td>
<td><?php echo $internship->name_enterprise_internship() ?></span></td>
<td><?php echo $internship->stage_internship() ?></span></td>
<td><input type="radio" name="apply" value="<?php $tabinternship->id_internship() ?>"></td> <!-- Method calls an Object rather than an Array because I'm only displaying the attributes of 1 Object therefore the Array is not required here-->
</tr>
<?php } ?>
</pre>
StudentController:
<pre>
$tabinternships = Db::getInstance()->select_internships();
if(isset($_POST['apply']) && isset($_POST['application'])){
$_SESSION['apply']= $_POST['apply'];
$_SESSION['application']= $_POST['application'];
$_SESSION['redirect']='redirect';
}
if(!empty($_SESSION['application']) && !empty($_SESSION['apply']) && !empty($_SESSION['redirect'])){
$_SESSION['redirect']='';
header("Location: index.php?action=formdeux");
die();
}
</pre>
感谢您的帮助。
【问题讨论】:
-
您的表单代码在哪里,并通过示例详细说明您的问题
-
我的错误应该是学生表格。我想通过为单选按钮提供行 ID 来识别行。这将在稍后用于查询,我想在 SESSION 中存储所选行的 ID。 @SamirKarmacharya
-
如果学生选择实习,我想将实习的 ID 存储在 SESSION 中。我想我可以将它存储在单选按钮的值内。我想对了吗?
-
$tabinternship->id_internship() 表中的值对吗?当第一个用户打开带有 id 的表单假设“10”同时用户打开表单并提交然后用户第一次提交时发生了什么。那么就会发生冲突。最好提取学生信息并添加唯一ID并插入数据库。
-
一次不会有多个用户,因此不会有任何冲突。我只想将 unique_id 存储在 SESSION 中以备后用。我不知道为什么“值”不能保存变量。如果有一种更简单的方法可以在 SESSION 中保留 ID,这将对我有很大帮助。感谢您的回答@SamirKarmacharya