Forum Moderators: coopster

Message Too Old, No Replies

Problem with creating a dynamic template page

         

ssandhu

10:17 pm on Mar 5, 2009 (gmt 0)

10+ Year Member



I have 2 images and I want it so that when i click on one image, it should print out some text saying "test1" and when i click on another image it should say "test2".
Below are the two images i created with a name to test the php script:

<div class="img"> <p>testing:</p> <input type="image"
src="Pictures/image1.jpg" name="test" width="200px" height="180px">
</div>

<div class="img"> <p>testing 2:</p> <input type="image"
src="Pictures/image2.jpg" name="test2" width="200px" height="180px">
</div>

Below is the php script:
<html>
<head>
Template
</head>

<body>

<h1>this is a test for the template</h1>

<?php
if($name==$_POST["test"]) {echo '<p>test1</p>';}
else if($name==$_POST["test2"]) {echo '<p>test2<p2>';}
?>

</body>
</html>.

The problem is, it prints out "test1" in both cases.

Help would be much appreciated. And I apologies if a similar thread has already been created.

Kind Regards

ssandhu

8:37 am on Mar 7, 2009 (gmt 0)

10+ Year Member



Is this the correct way of doing it or am i approaching it in the wrong way?

coopster

7:50 pm on Mar 7, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, ssandhu.

What is $name? I would probably use isset [php.net].

if (isset($_POST['test_x'])) { 
echo '<p>test1</p>';
} else if (isset($_POST['test2_x'])) {
echo '<p>test1</p>';
}

Note also the use of test_x for detecting input type image elements. Details can be found on the PHP and HTML [php.net] manual page. Firefox will pass back "test" as well as the x and y coordinates. Certain versions of MSIE will only pass back the x and y parts.

ssandhu

8:09 pm on Mar 7, 2009 (gmt 0)

10+ Year Member



Thanks for the reply Cooper, just tried it and it works.

I just started learning PHP, so i'm still a bit "Duh!".

Thanks again.

coopster

8:21 pm on Mar 7, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You're welcome. Here is another old thread regarding the same issue you are experiencing today. So, you see, you're not the only person that has hit this wall :)
Form processing problem with input type=image! [webmasterworld.com]

ssandhu

11:09 pm on Mar 7, 2009 (gmt 0)

10+ Year Member



Sorry, meant coopster*. :)

coopster

9:33 pm on Mar 8, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



No worries, I've been called worse ;)