I'm totally new to PHP, so I apologize if this seems pretty simple. I've gotten so much help on other problems from reading through this site and I've tried so many different examples of trying to solve this, but couldn't work this out yet.
I have a site that some users will include a link to their personal blog (external site) while others will not. I've set up a field in the mySQL table labeled blog
. The data inside the field is a full URL to include the http://
.
I want to display a message like: Visit my blog here
. With the here
being a link to the users blog site.
I have the following code
<?php
if (!isset ($blog))
{
?>
Visit my blog <a href="<?=$data['blog'];?>" target="_blank">here</a>
<?php
}
?>
The link works correctly, however, if the data field is empty, it still displays and the link is to the same page the code is on.
I've tried this code:
<?php
if (!isset ($blog))
{
echo "Visit my blog <a href=\" . $blog .\" target=\"_blank\">here</a>." ;
}
?>
This displays the echo
whether or not the field is blank AND the link is not pulling the data from the table.
I'm really at a loss as to what I'm doing wrong.
isset()
checks if the variable exists at all and ignores the value in the variable, e.g.so if your
$blog
EVER had a value assigned to it, it'llisset()
as true. You probably wantinstead.