|
-
Jan 23rd, 2010, 01:46 PM
#1
Thread Starter
Hyperactive Member
Assign & retrieve value from image in PHP
Hello,
I have a serious situation.
I have 10 different values in an array of PHP.
I have 10 different images in an HTML form.
I have to assign these 10 array values to 10 images. If I click an image then the corresponding value will be display.
My PHP code is below.
PHP Code:
<?php
if(isset($_POST["img"]))
{
echo $_POST["img"];
}
?>
But this is not working. Please help to overcome the situation.
Thanks & Regards.
-
Jan 23rd, 2010, 02:03 PM
#2
Re: Assign & retrieve value from image in PHP
uh. how about you show us your form because I'm not entirely sure what you're doing.
-
Jan 24th, 2010, 08:52 AM
#3
Hyperactive Member
Re: Assign & retrieve value from image in PHP
Agree with kows.
Sound like you need to look at multi-dimensional arrays. (see w3schools or php.net, depending on your level)
If you want to investigate what's posted use:
print_r($_POST);
-
Jan 24th, 2010, 11:41 AM
#4
Thread Starter
Hyperactive Member
Re: Assign & retrieve value from image in PHP
Here is my code. Please help.
PHP Code:
<?php
if(isset($_POST["img"]))
{
echo $_POST["img"];
}
else
{
$arr = array(1,3,6,87,23,7,33,12,5,54);
}
?>
HTML Code:
<html>
<head>
<title>Image</title>
</head>
<form name="f" method="post" action="<?php echo $_SERVER["PHP_SELF"] ?>">
<body>
<img id='$arr[0]' src='a.png' />
<img id='$arr[1]' src='a.png' />
<img id='$arr[2]' src='a.png' />
<img id='$arr[3]' src='a.png' />
<img id='$arr[4]' src='a.png' />
<img id='$arr[5]' src='a.png' />
<img id='$arr[6]' src='a.png' />
<img id='$arr[7]' src='a.png' />
<img id='$arr[8]' src='a.png' />
<img id='$arr[9]' src='a.png' />
</body>
</form>
</html>
-
Jan 24th, 2010, 12:24 PM
#5
Re: Assign & retrieve value from image in PHP
uhh.. but none of these images can be clicked on -- you don't have a link (<a>nchor tag) associated with them or any javascript to submit the form when you click on them. how do you expect PHP to interact with these? there's no way.
I still don't know what you're trying to do. instead of explaining an abstract situation, try explaining exactly what you want to do, with as much detail as possible to get the point across.
as a side note, you're defining your IDs wrong. IDs can't be defined the way you're doing it (with scalars ['$'] and square brackets), and IDs are not used by PHP (whereas in ASP.NET, they are). PHP uses the 'name' attribute associated with an <input> when you're dealing with POST. if you want to use images, you'll have to do something fancy with GET. it all depends on what you're actually doing, though.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|