gpt4 book ai didi

php - 我需要使用 PHP 创建的选择将数据从动态表插入 mysql

转载 作者:行者123 更新时间:2023-11-30 00:35:52 25 4
gpt4 key购买 nike

想知道是否有人可以帮助我使用 PHP 动态创建的几个选择中的数据来更新 mysql 表,我创建了以下代码,但它似乎不起作用,非常感谢您的帮助:

`include_once('../includes/connection.php');`




// Query that retrieves events
$con = "SELECT * FROM evenement WHERE approved = 'no' ORDER BY id";
$result = mysqli_query($connection, $con);
if($con){
$registry = mysqli_affected_rows($connection);

if($registry > 0){
echo '
<h1 align="center">Events pending approval</h1>
<br><table width="100%" align="center" border="0" border-spacing="2px" cellspacing="1" cellpadding="1">


<form action="approveReject.php" method="post" >
<tr bgcolor="#3333FF" style="color:white; font-family:Tahoma, Geneva, sans-serif; font-size:15px"">
<th align="center"><strong>Title</strong></th>
<th align="center"><strong>Details</strong></th>
<th align="center"><strong>Category</strong></th>
<th align="center"><strong>Start</strong></th>
<th align="center"><strong>End</strong></th>
<th align="center"><strong>All Day event?</strong></th>
<th align="center"><strong>Approved</strong></th>
</tr>';

$color = "1";
while($registry = mysqli_fetch_array($result, MYSQLI_ASSOC)){
if($color==1){
echo '<tr bgcolor="#F8F8F8" font-family:Tahoma, Geneva, sans-serif; font-size:15px">';
$color="2";
} else {
echo '<tr bgcolor="#dcdcdc" font-family:Tahoma, Geneva, sans-serif; font-size:15px">';
$color="1";
}

echo '
<form action="" method="post">
<input type="hidden" value="'.$registry['id'].'" name="id[]" id="id">
<th div align="center">'.$registry['title'].'
<td div align="center">'.$registry['details'].'
<td div align="center">'.$registry['category'].'
<td div align="center">'.$registry['start'].'
<td div align="center">'.$registry['end'].'
<td div align="center"><select name="allDay[]" id="allDay">
<option value="0">Select option</option>
<option value="1">Yes</option>
<option value="2">No</option>
</select>
<td div align="center"><select name="ap_re[]" id="ap_re">
<option value="0">Select option</option>
<option value="1">Yes</option>
<option value="2">No</option>
</select>


</tr>';


}

?>

<td><input type="submit" name="button" id="button" value="Submit" style="height:1.8em; width:7.3em;" /></td>

<?php

echo '</form>

';
echo '


</form>


</table>';
}

}else{
echo '<h1>There are no new requests to be approved</h1>';
}


if(isset($_POST['Submit'])){

if($_POST['allDay'] == 'Yes'){
$allDay = 'true';

}else{
$allDay = 'false';
}
$ap_re = $_POST['ap_re'];
$i = 0;

foreach($_POST['id'] as $id){

$udpate_qry = "UPDATE evenement SET allDay='".$allDay."', approved='".$ap_re."', WHERE id='".$id."'";
$result_udpate_qry = mysqli_query($connection, $update_qry);
$i++;

}
}

?>

最佳答案

我不认为我已经解决了您的所有问题,但这可能会进一步帮助您。

<?php

include_once('../includes/connection.php');


if (isset($_POST['submit'])) {

if ($_POST['allDay'] == 'Yes') {
$allDay = 'true';
} else {
$allDay = 'false';
}

$ap_re = $_POST['ap_re'];
$id = $_POST['id'];
$i = 0;
while ($id) {


$update_qry = "UPDATE evenement SET allDay='" . $allDay . "', approved='".$ap_re[$i]. "' WHERE id='".$id[$i]."'";

echo var_dump($update_qry);
mysqli_query($connection, $update_qry) OR DIE(mysqli_error($connection));
$i++;

}

header('Location: http://www.stockoverflow.com/'); // INSERT approveReject.php ???
}
else {





// Query that retrieves events
$con = "SELECT * FROM evenement WHERE approved = 'no' ORDER BY id";
$result = mysqli_query($connection, $con) or die(mysqli_error($connection));
if ($result) {
$registry = mysqli_num_rows($result) or die (mysqli_error($connection));

if ($registry > 0) {
echo '
<h1 align="center">Events pending approval</h1>
<br><table width="100%" align="center" border="0" border-spacing="2px" cellspacing="1" cellpadding="1">


<form action="" method="POST" >
<tr bgcolor="#3333FF" style="color:white; font-family:Tahoma, Geneva, sans-serif; font-size:15px"">
<th align="center"><strong>Title</strong></th>
<th align="center"><strong>Details</strong></th>
<th align="center"><strong>Category</strong></th>
<th align="center"><strong>Start</strong></th>
<th align="center"><strong>End</strong></th>
<th align="center"><strong>All Day event?</strong></th>
<th align="center"><strong>Approved</strong></th>
</tr>';

$color = "1";
while ($registry = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
if ($color == 1) {
echo '<tr bgcolor="#F8F8F8" font-family:Tahoma, Geneva, sans-serif; font-size:15px">';
$color = "2";
} else {
echo '<tr bgcolor="#dcdcdc" font-family:Tahoma, Geneva, sans-serif; font-size:15px">';
$color = "1";
}

echo '

<input type="hidden" value="' . $registry['id'] . '" name="id[]" id="id">
<th div align="center">' . $registry['title'] . '
<td div align="center">' . $registry['details'] . '
<td div align="center">' . $registry['category'] . '
<td div align="center">' . $registry['start'] . '
<td div align="center">' . $registry['end'] . '
<td div align="center"><select name="allDay[]" id="allDay">
<option value="0">Select option</option>
<option value="1">Yes</option>
<option value="2">No</option>
</select>
<td div align="center"><select name="ap_re[]" id="ap_re">
<option value="0">Select option</option>
<option value="1">Yes</option>
<option value="2">No</option>
</select>


</tr>';
}
?>

<input type="submit" name="submit" id="button" value="Submit" style="height:1.8em; width:7.3em;" />

<?php

echo '</form>

';
echo '


</form>


</table>';
}
} else {
echo '<h1>There are no new requests to be approved</h1>';
}

}

?>

关于php - 我需要使用 PHP 创建的选择将数据从动态表插入 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22186851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com