从mysql表中检索数据并将其放入输入中并更新数据

时间:2019-06-23 03:05:27

标签: php mysql

enter image description here我的代码可以从mysql表中检索数据。但是我无法更新检索到的数据。我相信代码是不言自明的。

<?php
session_start();
if($_SESSION['app'])
{
if(isset($_POST['submit']))
{
    $acadexamo = $_POST['acadexamo'];
    $acaddivio = $_POST['acaddivio'];
    $acadpco = $_POST['acadpco'];
    $acadyearo = $_POST['acadyearo'];
    $acadspeciao = $_POST['acadspeciao'];
    $acadboardo = $_POST['acadboardo'];
    $db = mysqli_connect('localhost','root','','test');
    $sqlz = mysqli_query($db, "
         SELECT id 
         FROM recru_quali 
         WHERE app='$_SESSION[app]'");
    $rowa = mysqli_fetch_assoc($sqlz);
    $maxqua = count($acadexamo);
    for($i=0;$i<$maxqua;$i++)


       {
        $sqla = mysqli_query($db, "
                UPDATE recru_quali 
                SET acadexam='$acadexamo[$i]',
                acaddivi='$acaddivio[$i]', 
                acadpc='$acadpco[$i]', 
                acadyear='$acadyearo[$i]', 
                acadspecia='$acadspeciao[$i]', 
                acadboard='$acadboardo[$i]' 
                WHERE id='$rowa[id]' 
                AND app = '$_SESSION[app]'");
        }
}
?>
<form method="post" action="" enctype="multipart/form-data">
<div class="tab"><h3 align="center">Academic Qualifications:</h3>
<table id="employee_tablezz" align="center" border="1" width="100%">
<div id="form_div">
<?php
$db = mysqli_connect('localhost','root','','test');
$sql = mysqli_query($db, "SELECT * FROM recru_quali WHERE 
app='$_SESSION[app]'");
$rows = mysqli_fetch_assoc($sql);
while($row = mysqli_fetch_assoc($sql))
{
?>
<tr><td><input type="text" name="acadexamo[]" value="<?php echo 
$row[acadexam]; ?>"></td>
<td><input type="text" name="acaddivio[]" value="<?php echo 
$row[acaddivi]; ?>"></td>
<td><input type="text" name="acadpco[]" value="<?php echo $row[acadpc]; ? 
>"></td>
<td><input type="text" name="acadyearo[]" value="<?php echo 
$row[acadyear]; ?>"></td>
<td><input type="text" name="acadspeciao[]" value="<?php echo 
$row[acadspecia]; ?>"></td>
<td><input type="text" name="acadboardo[]" value="<?php echo 
$row[acadboard]; ?>"></td></tr>
</table>
<button name="submit">Submit</button>
</form>
<?php
}
?>

上面的代码仅更新一行。请告诉我如何用相同的应用程序号更新所有行。我添加了图像。这些行已从数据库中检索出来并显示在输入中,以便用户可以对其进行修改。但不会。

0 个答案:

没有答案