简体   繁体   English

如何将表格中的数据插入到表格中

[英]How do I insert data from a table to a form

I have a form which I want to be auto-completed with data from a table I made.我有一个表格,我想用我制作的表格中的数据自动完成。 How can I achieve this?我怎样才能做到这一点? This is my table:这是我的桌子:

    while($row  = mysqli_fetch_assoc($result))
    {
        echo "<tr>";
        echo "<td>" . $row['ID_Angajati'] . "</td>";
        echo "<td>" . $row['Nume'] . "</td>";
        echo "<td>" . $row['Prenume'] . "</td>";
        echo "<td>" . $row['CNP'] . "</td>";
        echo "<td>" . $row['Data_Nasterii'] . "</td>";
        echo "<td>" . $row['Sex'] . "</td>";
        echo "<td>" . $row['Numar_Telefon'] . "</td>";
        echo "<td>" . $row['Salariu'] . "</td>";
        echo "<td class = container_update ><button type = 'button' onclick = 'yes_js_modal();'>Update</a></td>";
        echo "<td class = container_delete ><a href = 'includes/delete.php?id=$row[ID_Angajati]'>&times;</a></td>";
        echo "</tr>";
    }
    echo "</table>";

And this is my form:这是我的表格:

<form action="" method="POST">
<table align="center">

<tr>
<td>ID_Angajati:</td>
<td><input type = "text" name="ids" required></td>
</tr>

<tr>
<td>Nume:</td>
<td><input type = "text" name="nume" required></td>
</tr>

<tr>
<td>Prenume:</td>
<td><input type = "text" name="prenume" required></td>
</tr>

<tr>
<td>CNP:</td>
<td><input type = "text" name="cnp" required></td>
</tr>

<tr>
<td>Data Nasterii:</td>
<td><input type = "text" name="data" required></td>
</tr>

<tr>
<td>Sex:</td>
<td><input type = "text" name="sex" required></td>
</tr>

<tr>
<td>Numar Telefon:</td>
<td><input type = "text" name="nr_telf" required></td>
</tr>

<tr>
<td>Salariu:</td>
<td><input type = "text" name="sal" required></td>
</tr>

<tr>
<td colspan = "2" align = "center">
<input type="submit" id="button" name="submit" value="Update Details"></a>
</td>
</tr>

</table>
</form>

I want for instance ID_Angajati from my form to be auto-completed in the form with the value of one of my rows in the table.例如,我希望表单中的 ID_Angajati 在表单中自动完成,其中包含表中我的行之一的值。 This will happen when I click on the "Update" button from the table.当我单击表格中的“更新”按钮时,就会发生这种情况。

If you want to do it without sending the form you'll need Javascript.如果您想在不发送表格的情况下执行此操作,则需要 Javascript。 But if you want to do it with PHP, you can do it on the same file.但是如果你想用 PHP 来做,你可以在同一个文件上做。 By the way you did it, it will print all the data that you have on the database, but here is the code:顺便说一句,它将打印您在数据库中拥有的所有数据,但这里是代码:

<?php 
    function appear_form()
    {
        while($row = mysqli_fetch_assoc($result))
        {
            echo "<table align='center'>";
            echo "<tr>";
            echo "<td>ID_Angajati:</td>";
            echo "<td>{$row['ID_Angajati']}</td>";
            echo "</tr>";
            echo "<td>Nume:</td>";
            echo "<td>{$row['Nume']}</td>";
            echo "</tr>";
            echo "<td>Prenume:</td>";
            echo "<td>{$row['Prenume']}</td>";
            echo "</tr>";
            echo "<tr>";
            echo "<td>CNP:</td>"
            echo "<td>{$row['CNP']}</td>";
            echo "</tr>";
            echo "<tr>";
            echo "<td>Data Nasterii:</td>";
            echo "<td>{$row['Data_Nasterii']}</td>";
            echo "</tr>";
            echo "<tr>";
            echo "<td>Sex:</td>";
            echo "<td>{$row['Sex']}</td>";
            echo "</tr>";
            echo "<tr>";
            echo "<td>Numar Telefon:</td>";
            echo "<td>{$row['Numar_Telefon']}</td>";
            echo "</tr>";
            echo "<tr>";
            echo "<td>Salariu:</td>";;
            echo "<td>{$row['Salariu']}</td>";
            echo "</tr>";
            echo "</table>";
        }
      
    }

    if(isset($_POST['submit']))
    {
        
        appear_form();
    }
    
?>
<form action="" method="post">
    <button type="submit" id="submit" name="submit">Update Details</button>
</form> 

PHP interact with the server so it could only manage GET, POST, etc requests. PHP 与服务器交互,因此它只能管理 GET、POST 等请求。 If you want something more elaborated you'll need to use Javascript.如果您想要更详细的内容,则需要使用 Javascript。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM