Update data from a form

Viewed 22

I'm trying to modify some records by using a form in html and php, but I don't know the instruction to do it. I use a select tag, where the options are added by reading the database. So I need to update the data of the selected record. Anyone can help me?

1 Answers

after you get id

$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>

after that

<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>

create file update.php

$id = $_POST['id'];

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

reference link

Related