Jump to content

if and else problems


almightyegg

Recommended Posts

I have this code and my test user has info filled in their mysql row but still it says 'gah' to show an error :(

I am really stuck!! please help  ;D

[code=php:0]
<?
if($profile['customt1']==0){
echo "gah";
}else{
?>
<tr><td valign="top"><b><? echo "$profile[customt1]"; ?></b> </td>
<td valign="top"><? echo "<p>$profile[customtext1]</p>"; ?></td></tr>

<?
}
if($profile['customt2']==0){
echo "gah";
}else{
?>
<tr><td valign="top"><b><? echo "$profile[customt2]"; ?></b></td>
<td valign="top"><? echo "<p>$profile[customtext2]</p>"; ?></td></tr>

<?
}
if($profile['customt3']==0){
echo "gah";
}else{
?>
<tr><td valign="top"><b><? echo "$profile[customt3]"; ?></b> </td>
<td valign="top"><? echo "<p>$profile[customtext3]</p>"; ?></td></tr>
<? } ?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/35540-if-and-else-problems/
Share on other sites

Instead of comparing it to 0, try checking if it is set.
If I recall correctly,
if($profile['customt1']==0){
Will convert $profile['customt1'] to a number. Since it's not a number, it turns into 0. Thus, TRUE.

Try

if(!isset($profile['customt1'])){
// gah
}
Link to comment
https://forums.phpfreaks.com/topic/35540-if-and-else-problems/#findComment-168283
Share on other sites

[quote author=jesirose link=topic=123854.msg512514#msg512514 date=1169663792]
Now it doesn't display gah or your table?
What about

if(empty($profile['customt1'])){
[/quote]
It wouldn't display any of the page  ???


[quote author=steelmanronald06 link=topic=123854.msg512516#msg512516 date=1169663925]
it will have to be something like:

if (!$profile['custom1'])) {

echo 'gah';

}

Granted empty might work to, but I use the ! and it works fine on my sites.
[/quote]

It worked!!!! Thank you muchly! ;D
Link to comment
https://forums.phpfreaks.com/topic/35540-if-and-else-problems/#findComment-168379
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.