progresser progresser - 3 months ago 12
PHP Question

PHP If Else with isset: else part does not work

PHP Part is here So when I post it, else part does not work at all (meaning: the text I set just disappear), while the other half works (meaning: I can assign variables, but can't leave it blank). I have been struggling with it all night...please help!
So this is the second page, if you need to take a look at the code on the first page, please let me know!

<?php
$lovers = $_POST['lovers'];
$quote = $_POST['quote'];
$color = $_POST['color'];
$font = $_POST['font'];
$imdblink = $_POST['imdblink'];
?>

<?php
if (isset($_POST['lovers']))
{
$lovers = $_POST['lovers'];
}else{
echo "P & M";
}

if (isset($_POST['quote']))
{
$quote = $_POST['quote'];
}else{
echo "I love you.";
}

if (isset($_POST['color']))
{
$color = $_POST['color'];
}else{
echo "yellow";
}

if (isset($_POST['font']))
{
$font = $_POST['font'];
}else{
echo "Futura";
}

if (isset($_POST['imdblink']))
{
$imdblink = $_POST['imdblink'];
}else{
echo "http://www.imdb.com/";
}
?>


Here is the HTML part: Is there anything wrong here? Please help!

<div class="artGroup slide">
<div class="artwork"> <img src="../_images/M&P.png">
<div class="detail">
<div class="movie01c" style="font-family: <?php echo "{$font}"; ?>; font-size: 20px; color: <?php echo "{$color}";?>;">
<?php echo "{$quote}";?>
</div>
<div class="movie01t"><a href="<?php echo "{$imdblink}";?>">
<?php echo "{$lovers}";?>
</a></div>
</div>
</div>
</div>

Answer

Instead of using echo, use variable assignment too in the else part.

if (isset($_POST['lovers'])) {
    $lovers = $_POST['lovers'];
}else{
    $lovers = "P & M";
}