PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hi, I'm new to PHP (but not programming) and I can't get this comparison to work. $IDLevel is pulled from a MySQL database, and if I echo it it displays as "Administrator" (without the quotes), but for some reason the if($IDLevel == "Administrator") keeps returning false. I've tried using single quotes and no quotes, and also setting up a second variable for the right-hand operand, but nothing works. What am I doing wrong?
<?PHP
...
...
$row = mysql_fetch_assoc($result);
$IDLevel = $row[0];
/* I usually use the column name, as if you change the order, or add a new column in,
then you have to recode everything again. If you do, do this, then remember to add
single quotes around column name, so it would be: $IDLevel = $row['column'];
*/
if($IDLevel == "Administrator"){
?>
<div class="articles-admin">[<a href="edit-article.php?id=<?php echo"$IDLevel"; ?>">edit</a>]</div>
<?PHP
}
?>
There isn't any whitespace in the variable. Here's the entire script and output. I can't figure out why the comparison on line 48 isn't returning true.
i dont know if thats just temporary for debugiing,
but that will always be true, and as such is pointless. but thats def not your problem here. just wanted to point it out.
The $IDLevel == $IDLevel is just for debugging. The output of echo $IDLevel is "Administrator" (without the quotes). The capitalization matches. echo $IDLevel is done earlier in the script (line 16) just to test it, which you can see @ the top of the image.
litterally cut and paste that echo in the place i said to.
do not retype it, and do not put it somewhere else in the script. put it directly above the if statement.
either the output from the echo will be different, of the if statement will work. theres no other possibility.