Page 1 of 1

images

Posted: Wed Oct 26, 2005 3:50 am
by ben_albrechts
Can somebody help me please , i'm new to the whol php-programming thing.
I have a form on my website for my visitors , and depending on what they submit through the form I want a different picture/image to be shown.

so it shud be an if construction that basically does :
if blue then show the blue image , but how do i do that?

Thank you

Posted: Wed Oct 26, 2005 4:18 am
by mickd

Code: Select all

if($_POST['image'] == 'blue') {
echo '<img src="blue.jpg" alt="Blue" />';
} elseif($_POST['image'] == 'red') {
echo '<img src="red.jpg" alt="Red" />';
}

// etc
or you could use the switch command instead

PHP Manual - Switch

Posted: Wed Oct 26, 2005 4:58 am
by Jenk
Or something like:

Code: Select all

<?php

$images = array('blue', 'red', 'green', 'yellow', 'orange');

if (in_array($_POST['image'], $images)) {
    echo "<img src=\"{$_POST['image']}.jpg\" />";
} else {
    echo "<img src=\"default.jpg\" />";
}

?>
But do be careful when using user input, assume it is malicious in all circumstances. :)

Posted: Wed Oct 26, 2005 10:02 am
by ben_albrechts
thank you both. I'll try your ideas later n tonight , and if i have any more problems i'll be back with more questions :D