Ticker

6/recent/ticker-posts

Edit USER di PHP



Sebelum mengedit, alangkah baiknya tambahkan terlebih dahulu di  index.php

 <a href="edit.php" >Edit</a>

Menjadi

<a href="edit.php?id=<?php echo $d['id']; ?>" >Edit</a>

Edit Data PHP

EDIT.PHP

 

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>Edit Data User</title>

</head>

<body>


<h2 style="text-align: center;">Edit Pengguna</h2>

<br>


<?php

include '../../assets/koneksi.php';

$id = $_GET['id'];


$data = mysqli_query($con, "SELECT * FROM user WHERE id='$id'");

foreach ($data as $p) { ?>


<form method="post" action="aksi_edit.php">

<input type="hidden" name="id" value="" placeholder="Masukan Username">

<input type="text" name="username" value="<?= $p['username']; ?>" placeholder="Masukan Username">

<br><br>

<input type="password" name="password" value="<?= $p['password']; ?>" placeholder="Masukan Password">

<br>

<br>

<button type="submit">Edit/Update</button>

</form>

<?php } ?>


</body>

</html>


aksi_edit.php


<?php 

include '../../assets/koneksi.php';


$id   = $_POST['id'];

$username = $_POST['username'];

$password = $_POST['password'];



mysqli_query($koneksi,"UPDATE user SET username='$username', password='$password' where id='$id'");

 


header("location:index.php");

?>




Posting Komentar

0 Komentar