Fetch data to form


How can i fetch the values from the database and prefill the values in the form?



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']);
	$results = $records->fetch(PDO::FETCH_ASSOC);

	$user = NULL;

	if( count($results) > 0){
		$user = $results;


$message = '';

	// 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']);




<!DOCTYPE html>
	<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'>

	<div class="header">
		<a href="/">Äpplet Bonus</a>

	<?php if( !empty($user) ): ?>

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


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


	<?php endif; ?>



Like you are presently doing, with the exception of, you never fetch the values, you are just executing the statement. Execute the statement then assign those values to the variables being used.