I want the delete button to have an If statement inside my While loop so that the current user won’t be able to delete its account but it’s always having an error. What to do? Here’s my if statement btw;
<?php if($_SESSION["username"]!= $array[2]){
echo <a class="btn btn-danger delete_user" href="javascript:void(0)" data-id = '<?php echo $row['id'] ?>'>Delete</a>
}
and here is my while loop;
<?php while($array=mysqli_fetch_row($result)): ?>
<tr>
<td>
<?php echo $array[1];?>
<?php echo $array[2];?>
</td>
<td>
<?php echo $array[3];?>
</td>
<td>
<center>
<a class="btn btn-primary edit_user" href="javascript:void(0)" data-id = '<?php echo $row['id'] ?>'>Edit</a>
<a class="btn btn-danger delete_user" href="javascript:void(0)" data-id = '<?php echo $row['id'] ?>'>Delete</a>
</center>
</td>
</tr>
<?php endwhile; ?>
>Solution :
You didn’t mention the exact error, but I can see a few: String literals must always have quote marks round them, and also you can’t open a PHP block inside another one, or echo inside an echo.
Just close the php block before you start the HTML, and open it again afterwards for the closing bracket:
<?php if($_SESSION["username"]!= $array[2]) { ?>
<a class="btn btn-danger delete_user" href="javascript:void(0)" data-id = '<?php echo $row['id'] ?>'>Delete</a>
<?php } ?>