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
images
Moderator: General Moderators
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" />';
}
// etcPHP Manual - Switch
Or something like:
But do be careful when using user input, assume it is malicious in all circumstances. 
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\" />";
}
?>-
ben_albrechts
- Forum Commoner
- Posts: 33
- Joined: Wed Oct 26, 2005 3:33 am