【问题标题】:Update data from a form从表单更新数据
【发布时间】:2022-09-24 08:38:56
【问题描述】:

我正在尝试使用 html 和 php 中的表单来修改一些记录,但我不知道执行此操作的说明。 我使用select 标签,通过读取数据库添加选项。所以我需要更新所选记录的数据。 任何人都可以帮助我吗?

标签: php mysql


【解决方案1】:

拿到身份证后

$id = $_GET['id'];
$data = mysqli_query($con,"select * from a where id='$id'");
    while($d = mysqli_fetch_array($data)){
        ?>
<form method="post" action="update.php">
            <table>
<tr>            
                    <td>Name</td>
                    <td>
                        <input type="hidden" name="id" value="<?php echo $d['id']; ?>">
                        <input type="text" name="name" value="<?php echo $d['name']; ?>">
                    </td>
                </tr>

在那之后

<form method="post" action="update.php">
<table>
    <tr>            
        <td>Name</td>
        <td>
            <input type="hidden" name="id" value="<?php echo $d['id']; ?>">
            <input type="text" name="name" value="<?php echo $d['name']; ?>">
        </td>
    </tr>

创建文件 update.php

$id = $_POST['id'];

$name = $_POST['name']; mysqli_query($koneksi,"update mahasiswa set nama='$nama', nim='$nim', alamat='$alamat' where id='$id'");

参考link

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-08
    • 1970-01-01
    • 1970-01-01
    • 2018-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多