<label>Branches</label>
<br>
<script type="text/javascript">
<!--
document.write('<textarea class="form-control" style="resize:none;" id="area" rows="3" readonly="readonly"></textarea>')
function updateArea (e) {
document.getElementById('area').value = '';
for (var i=0; i<e.form.elements.length; i++){if (e.form.elements[i].type == 'checkbox' && e.form.elements[i].checked) {document.getElementById('area').value += e.form.elements[i].nextSibling.data; document.getElementById('area').value += '\n';}};
}
// -->
</script>
<p>
<div class="form-control" style="float:left;
height: 100px;
overflow: auto;">
<?php
$select = "SELECT * FROM branches WHERE access = 'User'";
if($result = mysqli_query($conn, $select)){
while ($row = mysqli_fetch_array($result)) {
$brid = $row['brid'];
?>
<input type="checkbox" name="brid[]" value="<?php echo $brid; ?>" onclick="updateArea(this)"><?php echo $brid; ?>
<input type="hidden" name="pangkat" value="<?php echo $pangkat; ?>">
<br>
<?php
}
}
?>
</div>
这里是我从分支表中选择brid的代码我已经知道如何将多行选定分支插入数据库我想知道如何在选择时插入分支的pangkat。
<?php
require '../db/db.php';
$smsid = $_POST['smsid'];
$brid = $_POST['brid'];
$pangkat = $_POST['pangkat'];
$smssubject = $_POST['smssubject'];
$smscontent = $_POST['smscontent'];
$smsfrom = $_POST['smsfrom'];
for ($i = 0; $i<sizeof($brid); $i++ ){
$insert = $conn->query("INSERT INTO messages(sms_id,brid,pangkat,subject,message,from_brid,datesent)
VALUES('$smsid', '".$brid[$i]."','$pangkat',
'$smssubject','$smscontent','$smsfrom',NOW())");
echo "<script>alert('The Message is successfully sent');</script>";
echo "<script>window.location.assign('../load/amessages.php')</script>";
}?>
这是我的操作页面插入brid但pangkat总是空白任何帮助?
答案 0 :(得分:-1)
<?php
require '../db/db.php';
$smsid = $_POST['smsid'];
$brid = $_POST['brid'];
// $pangkat = $_POST['pangkat'];
$smssubject = $_POST['smssubject'];
$smscontent = $_POST['smscontent'];
$smsfrom = $_POST['smsfrom'];
for ($i = 0; $i<sizeof($brid); $i++ ){
$select = $conn->query(" SELECT * FROM branches WHERE brid = '".$brid[$i]."' ");
while($rows = mysqli_fetch_array($select)){
$pangkat = $rows['pangkat'];
$insert = $conn->query("INSERT INTO messages(sms_id,brid,pangkat,subject,message,from_brid,datesent)
VALUES('$smsid', '".$brid[$i]."','$pangkat',
'$smssubject','$smscontent','$smsfrom',NOW())");
echo "<script>alert('The Message is successfully sent');</script>";
echo "<script>window.location.assign('../load/amessages.php')</script>";
}
}?>
问题解决了谢谢!