944,110 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 7872
  • PHP RSS
Jul 31st, 2007
0

images and drop down list boxes

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
piers is offline Offline
68 posts
since Jul 2007
Aug 1st, 2007
0

Re: images and drop down list boxes

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

php Syntax (Toggle Plain Text)
  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. ?>
Reputation Points: 27
Solved Threads: 14
Junior Poster
Cerberus is offline Offline
162 posts
since Sep 2006
Aug 3rd, 2007
0

Re: images and drop down list boxes

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.
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
piers is offline Offline
68 posts
since Jul 2007
Aug 3rd, 2007
0

Re: images and drop down list boxes

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.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Aug 3rd, 2007
0

Re: images and drop down list boxes

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='' />";
?>
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
piers is offline Offline
68 posts
since Jul 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: AJAX And PHP
Next Thread in PHP Forum Timeline: Website that generates graphs and charts





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC