Hello,
I am having a problem with if and elseif statements. For whatever reason, it always goes to the first "if" statement rather than what it's supposed to go to. I have a selecting option box (dropdown menu) in a form and want to post it using the GET method. Once that's done, you submit the form. Let's say you pick "Orange". It still goes to red be default! Why could this be? Thanks in advance.
<?php
$text = $_GET['text'];
$color = $_GET['color'];
if ($color = "red") {
$image = imagecreatefrompng("/home/john1704/public_html/dynamic-images/images/redbutton.png");
}
elseif ($color = "blue") {
$image = imagecreatefrompng("/home/john1704/public_html/dynamic-images/images/bluebutton.png");
}
elseif ($color = "orange") {
$image = imagecreatefrompng("/home/john1704/public_html/dynamic-images/images/orangebutton.png");
}
elseif ($color = "yellow") {
$image = imagecreatefrompng("/home/john1704/public_html/dynamic-images/images/yellowbutton.png");
}
elseif ($color = "green") {
$image = imagecreatefrompng("/home/john1704/public_html/dynamic-images/images/greenbutton.png");
}
elseif ($color = "purple") {
$image = imagecreatefrompng("/home/john1704/public_html/dynamic-images/images/purplebutton.png");
}
else {
echo "Color not selected.";
}
$coloroftext = imagecolorallocate($image, $_GET['color1'], $_GET['color2'], $_GET['color3']);
header("Content-type: image/png");
imagettftext($image, 10, 0, 20, 30, $coloroftext, "arial", $text);
imagepng($image);
imagedestroy($image);
?>
Here is the form:
<form action="buttoncreator.php" method="GET">
<input type="text" name="text" value="Text of Button"><br>
Color of button: <select name="color">
<option value="red">Red</option>
<option value="orange">Orange</option>
<option value="yellow">Yellow</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
<option value="purple">Purple</option>
</select><br>
RGB Code of Text: <input type="text" name="color1" value="255">-<input type="text" name="color2" value="255">-<input type="text" name="color3" value="255"><br>
<input type="submit" value="Create">-<input type="reset" value="Reset">
</form>