I am trying to display information about currently logged in user. The problem is information I need are in two differnet tables so I had to use INNER JOIN and I have problem to display data.
<?php
$email = $_SESSION['email'];
$sql_address =
"SELECT `customer`.`email`, `address`.`first_name`, `address`.`last_name`
FROM `customer` INNER JOIN address ON `customer`.`customer_ID`=`address`.`customer_ID WHERE email =". $email;
$result_address = $db->query($sql_address);
if(isset($_SESSION['email'])){
while($row = mysqli_fetch_array($result_address)){ ?>
<div class="col-sm-4 mb-20">
<div class="mb-20 mb-md-10">
<h3> CUSTOMER DETAILS</h3>
<p>Name: <?php echo $row['first_name']. " " .$row['last_name'];?><br/>
Email: <?php echo $row['email'];?>
</p>
</div>
</div>
<?php }?>
At this moment I am getting this error :
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in D:\xamp\htdocs\exercises\website\shipment.php on line 149
Can you please tell me where is a problem? Also do you have any suggestion how to make it more secure? I guess putting $email
into query
is probably not the best idea.
Probably You have an error in sql statement, so $result_address is false. $email should be in single quotes, and also add close quote to the `customer_ID
Try this query
SELECT `customer`.`email`, `address`.`first_name`, `address`.`last_name`
FROM `customer` INNER JOIN address ON `customer`.`customer_ID`=`address`.`customer_ID` WHERE email = '". $email . "'";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.