Exception or error:
I am new to PHP but working on this below. If I specify the email address, it will fetch the orders of the particular email address but I want it to pick the email address of the active session user and fetch the orders of the user. How do I work around this? Hoping to get helped.
<?php
require("db.php");
error_reporting(~E_NOTICE);
session_start();
$email = $_SESSION['email'];
$stmt=$db->prepare("select * from user where email=email");
$stmt->execute(array('email'=>$_SESSION['email']));
$row=$stmt->fetch(PDO::FETCH_ASSOC);
$count=$stmt->rowCount();
?>
<tbody>
<?php
$email = $_SESSION['email'];
$query=$db->query('select * from sellorder where email = "'.$_SESSION['email'].'"');
while($roww=$query->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php echo '<span class="text-dark">'.$roww["orderno"].'</span>'; ?></td>
<td><?php echo '<span class="text-dark">'.$roww["date"].'</span>'; ?></td>
<td><?php echo '<span class="text-dark">'.$roww["btcvalue"].'</span>'; ?></td>
<td>$<?php echo '<span class="text-dark">'.$roww["usdvalue"].'</span>'; ?></td>
<td>₦<?php echo '<span class="text-dark">'.$roww["nairavalue"].'</span>'; ?></td>
<td><?php echo '<span class="text-dark">'.$roww["accountno"].'</span>'; ?></td>
<td><?php echo '<span class="text-success">'.$roww["status"].'</span>'; ?></td>
</tr>
<?php
}
?>
</tbody>
How to solve:
You’re not using placeholders correctly in the first query. You’re asking for all records where the email
column equals the email
column. It should be:
"select * from user where email=:email"
The second one does not have a placeholder at all which is a huge mistake. Always use placeholder values:
$stmt=$db->prepare('select * from sellorder where email = :email');
$stmt->execute(['email' => $_SESSION['email']]);
while($roww=$stmt->fetch(PDO::FETCH_ASSOC))