1
<?php 
include('connect.php');
$query=mysqli_query($con,"select * from registration");
while($data=mysqli_fetch_array($query)) {
    $a15=$data['status'];
?>
<tr>
  <td><?php echo $data['name']; ?></td>
  <td><?php echo $data['email']; ?></td>
  <td><?php echo $data['contact']; ?></td>
  <td><?php echo $data['city']; ?></td>
  <td><?php echo $data['status']; ?></td>
  <td>
      <?php
      if($data['status']='pending') { ?>
      <a href="approve.php?id=<?php echo $data['id'];?>"><button Class="btn btn-primary btn-sm">Approve</button></a>
      <?php } else { ?>
      <a href="approve.php?id=<?php echo $data['id'];?>"><button Class="btn btn-success btn-sm">Approved</button></a>
      <?php } ?>
      <a href="delete.php?uid=<?php echo $data['id'] ?>"><button Class="btn btn-danger btn-sm">Delete</button></a>
  </td>
</tr>
<?php } ?>

This code is to print "approve" if user is not approved and print "approved" if user is already approved, but it's not working, showing approve in all cases

Komal12
  • 3,340
  • 4
  • 16
  • 25
Deepak
  • 54
  • 8

3 Answers3

7

Change

if($data['status']='pending')

To

if($data['status']=='pending') 

Edit:

if($data['status'] === 'pending') 

Will check the value as well as types.

For more info, click Comparison Operators

Nana Partykar
  • 10,556
  • 10
  • 48
  • 77
  • worth noting that `==` is a loose comparison that doesn't regard var_types `===` is strict and matches value and var_type – treyBake Jul 20 '17 at 10:22
  • Thankew so much.. its just slipped from my mind, btw thankew so much :) – Deepak Jul 20 '17 at 10:25
  • 1
    It was a typo @Deepak. If you think, this answer helped you. Then, please mark this answer as a correct answer. It will help other user to find this easily. – Nana Partykar Jul 20 '17 at 15:35
2

Insted of this

if($data['status']='pending')

use

if($data['status']==='pending')

For also check datatype.

Ajay Korat
  • 716
  • 4
  • 14
1

insted of this

'=' assignment operator

if($data['status']='pending')

use this code

'=='Comparison operators

if($data['status']=='pending')