editform.php
<?phpinclude "connect.php";
$id=$_GET["id"];
$sql="select * from tb_user where id =?";
$qr=$con->prepare($sql);
if($qr===false){
trigger_error("wrong sql".$sql."error".$con->error,E_USER_ERROR);
}
$qr->bind_param("i",$id);
$qr->execute();
$rs=$qr->get_result();
$rs->fetch_all();
foreach($rs as $edit);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>edit user</title>
</head>
<body>
<h1>edit form</h1>
<form name="edit" action="edit_db.php" method="post">
<label id="username">username</label>
<input type="text" name="username" id="username" value="<?php echo $edit["username"]; ?>"><br>
<label id="password">password</label>
<input type="password" name="password" id="password"value="<?php echo $edit["password"]; ?>"><br>
<label id="name">name</label>
<input type="text" name="name" id="name"value="<?php echo $edit["name"]; ?>"><br>
<label id="lastname">lastname</label>
<input type="text" name="lastname" id="lastname"value="<?php echo $edit["lastname"]; ?>"><br>
<label id="mobile">mobile</label>
<input type="text" name="mobile" id="mobile"value="<?php echo $edit["mobile"]; ?>"><br>
<label id="email">email</label>
<input type="text" name="email" id="email"value="<?php echo $edit["email"]; ?>"><br>
<label id="address">address</label>
<textarea name="address" id="address" cols="50" rows="10"><?php echo $edit["address"]; ?></textarea><br>
<input type="hidden" name="id" id="id" value="<?php echo $edit["id"]; ?>">
<input type="submit" name="btn_submit" id="btn_submit" value="save!!">
</form>
</body>
</html>
edit_db.php
<?phpinclude "connect.php";
$data=array(
"username"=>$_POST["username"],
"password"=>$_POST["password"],
"name"=>$_POST["name"],
"lastname"=>$_POST["lastname"],
"mobile"=>$_POST["mobile"],
"email"=>$_POST["email"],
"address"=>$_POST["address"],
"id"=>$_POST["id"],
);
$sql="update tb_user set username = ?
,password=?
,name=?
,lastname=?
,mobile=?
,email=?
,address=?
where id =?
";
$qr=$con->prepare($sql);
if($qr===false){
trigger_error("wrong sql".$sql."error".$con->error,E_USER_ERROR);
}
$qr->bind_param("sssssssi",$data["username"],$data["password"],$data["name"],$data["lastname"],$data["mobile"],$data["email"],$data["address"],$data["id"]);
$qr->execute();
echo "update to db ",$qr->affected_rows,"row";
$qr->close();
?>