hi I am new to this forum and new to using php. Everyone says it is really easy and so far so good until I was trying to display pictures based on the selected option from a drop down menu.

so I have 3 options:
dromidary
bactrian
mollie

I have an image from each. so I sent the form in the localhost from the HTML document to my php document using my webrowser but the pictures I cannot get to appear. This is my php code so far

<?php
$Fname = $_POST["txta"];
$add1 = $_POST["txtb"];
$add2 = $_POST["txtc"];
$add3 = $_POST["txtd"];
$postcode = $_POST["txte"];
$EM= $_POST["txtf"];
$mob= $_POST["txtg"];
$sex = $_POST["gender"];
$cam = $_POST["camel"];
$inv = $_POST["invoice"];
$subm = $_POST["sub"];
$TOT =500;
$B = $TOT * 17.5/100;
$A = $B + $TOT;
echo "INVOICE","<br>","<br>","<br>";

echo "name- ", $Fname,"<br>";
echo "adress1- ", $add1,"<br>";
echo "adress2- ",$add2,"<br>";
echo "adress3- ",$add3,"<br>";
echo "postcode- ",$postcode,"<br>";
echo "Email- ",$EM,"<br>";
echo "mobile- ",$mob,"<br>";
echo "sex of camel- ",$sex,"<br>";
echo"camel name-", $cam, "<br>";
echo "information will be sent to you via-",$inv,"<br>","<br>","<br>";
echo "subtotal:","£",$TOT,"<br>";
echo "vat is 17.5% is:",$B,"<br>";
echo "total cost:","£",$A;

if ($cam = camelx)
require ("maledromidary.jpg");

elseif ($cam = camely)
require ("malebactrian2.jpg");

else ($cam= camelz)
require ("mollie.jpg");

?>

Now I couldnt work out how to set it up as an array cus I dont know if it is possible to do super and subvariables. So I tried it as an if statement and i did nothing. This php page is an invoice showing the data That is typed in on the form and I just want to be able to display the pictures at thebottom of the page depending on the choise that is selected.

You can just turn of the php tags or echo the img tag

if ($cam == camelx)
{
   ?>
      <img src="maledromidary.jpg" alt="" />
   <?php
}
elseif ($cam == camely)
    echo "<img src='malebactrian2.jpg' alt='' />";
?>

thnx for showing me that. I now have this code


if ($cam == camelx)
{
?>
<img src="maledromidary.jpg" alt="" />;
<?php
}
elseif ($cam == camely)
{
?>
"<img src='malebactrian2.jpg' alt='' />";
}
<?php
($cam== camelz)
elseif "<img src='malebactrian2.jpg' alt='' />";
?>

I am getting this error
Parse error: syntax error, unexpected T_ELSEIF in C:\xampp\htdocs\invoice.php on line 45

now line 45 is the line I have put in bold.
I see the logic in what you are saying but I dont understand why it is a parse error usually I only get that if I have missed out the semi-colon but I havnt.

the elseif needs to be inside in front of the condition, you have it on the line below in front of a string for your img tag (which also won't work right). Also, you've gotten your php code and html tangled up in the last couple of cases. Check your php tags.

thnx a lot because it really helped. Now I read that if you put html code inside php it echos the HTML code and then the browser reads the html code so I tried to do that with this because I reaised with the other code that all pictures were showing one on top of the other and so using the echo seemed the sensible way but my browser doesnt seem to detect the html.

if ($cam == camelx)
{
echo "<img src='maledromidary.jpg' alt='' />";
}
elseif ($cam == camely)
{
echo "<img src='malebactrian2.jpg' alt='' />";
}
elseif ($cam == camelz)
echo "<img src='mollie.jpg' alt='' />";
?>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.