[英]How to post a checkbox value with database content in it? PHP&MYSQL
I got the following issue. 我遇到了以下问题。 I want to set a value from a database query to a checkbox value and then post the checkbox value to another file.
我想将数据库查询中的值设置为复选框值,然后将复选框值发布到另一个文件。
$sql = "SELECT * FROM Kunde WHERE UserID = $UserID";
foreach ($db->query($sql) as $zeile)
{
echo "<tr>";
//echo "<td>"; echo $zeile['id']; echo "</td>";
echo "<td>"; echo $zeile['Name']; echo "</td>";
echo "<td>"; echo $zeile['Vorname']; echo "</td>";
echo "<td>"; echo $zeile['Strasse']; echo "</td>";
echo "<td>"; echo $zeile['PLZ']; echo "</td>";
echo "<td>"; echo $zeile['Ort']; echo "</td>";
echo "<td>"; echo $zeile['Rufnummer']; echo "</td>";
echo "<td>"; echo $zeile['Email']; echo "</td>";
echo "<td>"; echo $zeile['Datum']; echo "</td>";
echo "<td>"; echo $zeile['Verlauf']; echo "</td>";
echo "<form action='update.php' method='post'>";
$id = $zeile['id'];
echo "<td>"; echo "<label>"; echo '<input type="checkbox" name="edit" value="'; echo $id; echo '"/>'; echo "</label>"; echo "</td>";
echo "<td>"; echo "<label>"; echo '<input type="checkbox" name="delete">'; echo "</label>"; echo "</td>";
echo "<td>"; echo "<button type='submit' class='submit'>Submit</button>"; echo "</td>";
Is this even possible? 这有可能吗? I also tried
我也试过
echo '<input type="checkbox" name="edit" value="'; echo $zeile['id']; echo '"/>';
but without success. 但没有成功。 Any ideas to manage this would be great.
任何解决这个问题的想法都很棒。 THX
谢谢
You cannot set the value of a checkbox, but you can have a hidden input that holds a value for the checkbox. 您不能设置复选框的值,但是可以具有一个隐藏的输入,其中包含该复选框的值。
<input type='checkbox' name='myCheckbox' />
<input type='hidden' name='myCheckbox_data' value='<?= $data ?>' />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.