images and drop down list boxes

Reply

Join Date: Jul 2007
Posts: 57
Reputation: piers is an unknown quantity at this point 
Solved Threads: 2
piers piers is offline Offline
Junior Poster in Training

images and drop down list boxes

 
0
  #1
Jul 31st, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 162
Reputation: Cerberus is an unknown quantity at this point 
Solved Threads: 14
Cerberus Cerberus is offline Offline
Junior Poster

Re: images and drop down list boxes

 
0
  #2
Aug 1st, 2007
You can just turn of the php tags or echo the img tag

  1. if ($cam == camelx)
  2. {
  3. ?>
  4. <img src="maledromidary.jpg" alt="" />
  5. <?php
  6. }
  7. elseif ($cam == camely)
  8. echo "<img src='malebactrian2.jpg' alt='' />";
  9. ?>
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 57
Reputation: piers is an unknown quantity at this point 
Solved Threads: 2
piers piers is offline Offline
Junior Poster in Training

Re: images and drop down list boxes

 
0
  #3
Aug 3rd, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,424
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 507
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: images and drop down list boxes

 
0
  #4
Aug 3rd, 2007
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.
Last edited by Ezzaral; Aug 3rd, 2007 at 2:39 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 57
Reputation: piers is an unknown quantity at this point 
Solved Threads: 2
piers piers is offline Offline
Junior Poster in Training

Re: images and drop down list boxes

 
0
  #5
Aug 3rd, 2007
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='' />";
?>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC