Results 1 to 5 of 5

Thread: Assign & retrieve value from image in PHP

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    266

    Question 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.

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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.

  3. #3
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    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);

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    266

    Question 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>

  5. #5
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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
  •  



Click Here to Expand Forum to Full Width