I try print the value of the database's row in input field, but I failed. The code runs, and nothing error is displayed.
How can I show the datas in the input values?
Class file
public function getDatas($field, $id) {
if ($result = $this->db->query("SELECT $field FROM user WHERE id = $id")) {
if ($result->num_rows) {
while ($string = $result->fetch_assoc()){
$value = $string[$field];
}
return $value;
}
$result->free();
}
}
html
<?php
$user = new User;
?>
<input class="form-control" type="text" id="name" name="name" value="<?php echo $user->getDatas('name', $_SESSION['id']);?>" required autocomplete="off">
<?php unset($user);?>