I am trying to re-display information from a table onto a form with the information I get is where id= userid.
I think the only problem I am having is that don't understand how to use the result as some type of name to put the results into my form since I am using tokens(so the user can see what they put as their favorite food when they initially set up the account.
For example if it selects from a row of data that already exists where id= user_id how do I do something like this after the query below?
I am currently using:
$row = $stmt->fetchAll(); shown on bottom before the form This can't be correct so I think I need something like the code below but I don't understand what it's doing or even how to write it correctly (i found this somewhere and I think it's close?)
while($res = fetch_array($result)) { $name = $res['name']; $age = $res['favfood']; $email = $res['email']; }
// Everything below this point in the file is secured by the login system
// We can retrieve a list of members from the database using a SELECT query.
// In this case we do not have a WHERE clause because we want to select all
// of the rows from the database table.
$query_params = array(
':user_id' => $_SESSION['user']['id'],
);
$query = "
SELECT
username,
favoritefood,
email
FROM order1new
WHERE id = :user_id
";
try
{
// These two statements run the query against your database table.
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
$stmt->execute();
}
catch(PDOException $ex)
{
// Note: you should not output $ex->getMessage().
// It may provide an attacker with helpful information about your code.
die("Failed to run query: " . $ex->getMessage());
}
// Here I am trying to retrieve all of the information I need and put it into the form below?
fetchAll
$row = $stmt->fetchAll();
?>
form name ="favfood" action="favfood.php" method="post">
Username:<br />
<input type="text" name="username" value="<?php echo htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8'); ?>" readonly>
<br /><br />
Food:<br />
**<!--//figure out how to find these ECHO $ FOOD STUFFS!!!!-->
<input type="number" name="favfood" value=<?php echo $favfood; ?> />
<br /><br />**
Email:<br />
<input type="email" name="email" value="<?php echo $email; ?>" />
<br /><br />
<input type="submit" value="Submit" />
</form>