How can i fetch the values from the database and prefill the values in the form?
<?php
session_start();
require 'database.php';
if( isset($_SESSION['user_id']) ){
$records = $conn->prepare('SELECT id,email,password FROM users WHERE id = :id');
$records->bindParam(':id', $_SESSION['user_id']);
$records->execute();
$results = $records->fetch(PDO::FETCH_ASSOC);
$user = NULL;
if( count($results) > 0){
$user = $results;
}
}
$message = '';
if(!empty($_POST['personnummer'])):
// Enter the new user in the database
$sql = "SELECT personnummer, fornamn, efternamn, bonus FROM customer WHERE personnummer = :personnummer";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':personnummer', $_POST['personnummer']);
$stmt->execute;
endif;
?>
<!DOCTYPE html>
<html>
<head>
<title>Äpplet Bonus</title>
<link rel="stylesheet" type="text/css" href="assets/css/style.css">
<link href='http://fonts.googleapis.com/css?family=Comfortaa' rel='stylesheet' type='text/css'>
</head>
<body>
<div class="header">
<a href="/">Äpplet Bonus</a>
</div>
<?php if( !empty($user) ): ?>
<br>
<a href="addcustomer.php">Lägg till kund</a>
<a href="addbonus.php">Lägg till bonus</a>
<a href="usebonus.php">Använd bonus</a>
<a href="logout.php">Logga ut</a>
<form action="usebonus3.php" method="POST">
<input type="text" value="<?php echo $personnummer ?>" name="personnummer" disabled>
<input type="text" value="<?php echo $fornamn ?>" disabled>
<input type="text" value="<?php echo $efternamn ?>" disabled>
<input type="text" value="<?php echo $bonus ?>" disabled>
<input type="submit" value="Använd bonus">
</form>
<?php else: ?>
<form action="login.php" method="POST">
<input type="text" placeholder="Epostadress" name="email">
<input type="password" placeholder="Lösenord" name="password">
<input type="submit" value="Logga in">
</form>
<?php endif; ?>
</body>
</html>