tags:

views:

17

answers:

2

I've made a simple guestbook mysql/php page. An entry is displayed if the approve column has a value of 1. For the adminstrator, I want to display either "message approved" or "not approved". Here's my code:

while ($row = mysql_fetch_array ($r)) {
    print "<p>Guest:" .$row['name']. "</p>
        <p>Date:" .$row['date']. "</p>
        <p>Comment:". $row['comment']. "</p>";

if ($row['approve'] = '1') { 
    print '<p>YES, the message has been approved</p>';
} else { 
    print '<p>NO, it hasn\'t been approved</p>';
}

Whatever value the if statement checks approve is equal to, all approve values are output as that value.

A: 

You used an assignment (=) instead of a comparison (==). It should be:

if ($row['approve'] == '1')
Michael Mrozek
+1  A: 

Your code $row['approve'] = '1' assigns $row['approve'] to '1' and evaluates to true if the assigned value does (and '1' does). If you want to compare the two values instead, you have to use the == operator.

Lukáš Lalinský