Can't find an input type=image value in $_POST

15,449

Just use var_dump() to see what's in $_POST :

var_dump($_POST);

And you'll see that, when your form is submitted using the <input type="image">, you get :

array
  'buyuka_x' => string '0' (length=1)
  'buyuka_y' => string '0' (length=1)


So, there is no $_POST['buyuka'] -- instead, there are :

  • $_POST['buyuka_x']
  • and $_POST['buyuka_y']

Which means your code should look like this (not testing for the unexistant buyuka entry, and testing for the two _x and _y -- I suppose that testing for one of those should be enough) :

if(isset($_POST['buyuka_x'], $_POST['buyuka_y']))
{
    $sorgu='SELECT * FROM urunler ORDER BY uyeno DESC';
}



Edit after the comments : I have no idea why it goes like that -- but having a .x and a .y is how it's defined in the HTML standard.

If you take a look at Forms in HTML documents, and scroll down a little, you'll be able to read :

When a pointing device is used to click on the image, the form is submitted and the click coordinates passed to the server.
The x value is measured in pixels from the left of the image, and the y value in pixels from the top of the image.
The submitted data includes name.x=x-value and name.y=y-value where "name" is the value of the name attribute, and x-value and y-value are the x and y coordinate values, respectively.

In PHP, the dots in parameters names are automatically replaced by and unerscore.
So :

  • name.x becomes name_x
  • and name.y becomes name_y

As a source for that last statement, you can read Variables From External Sources - HTML Forms (GET and POST) (quoting) :

Dots and spaces in variable names are converted to underscores.
For example <input name="a.b" /> becomes $_REQUEST["a_b"].

Share:
15,449
Admin
Author by

Admin

Updated on June 23, 2022

Comments

  • Admin
    Admin almost 2 years

    Well may be it is to easy question but:

    I want to sort the numbers by clicking an image. I thought that i make a form and add an imagefield.

    <form id="form1" name="form1" method="post" action="index.php">
    <input name="buyuka" type="image" src="resimler/azalt.gif" />
    </form>
    

    Then i will write these codes.

    $sorgu='SELECT * FROM urunler';
    
    if(isset($_POST['buyuka'])
    
    {
        $sorgu='SELECT * FROM urunler ORDER BY uyeno DESC';
    }
    
    $sonuclar=mysql_query($sorgu);
    

    However it doesn't sort. When i try adding submit button in order to add imagefield, it works. So it means i make a really basic mistake but i cant find it.

    Thank you for helping. :)

    EDIT --- Solved

    Actually as Pascal Martin said:

    if(isset($_POST['buyuka_x'], $_POST['buyuka_y']))
    {
        $sorgu='SELECT * FROM urunler ORDER BY uyeno DESC';
    }
    

    It must be like that. Thanks :)

  • Pascal MARTIN
    Pascal MARTIN about 13 years
    @Charles : now, you do ;-) (and it's soo useful ;-) )
  • ceejayoz
    ceejayoz about 13 years
    input ids are ignored by the server.
  • Charles
    Charles about 13 years
    I'm not sure who downvoted you, but the input id attribute is not submitted when posted.
  • markus
    markus about 13 years
    I want to see the face behind that hand.
  • mdubulous
    mdubulous about 13 years
    I see. Just noticed it was missing, and because I have never come across the same problem he is having thought that might help.
  • Admin
    Admin about 13 years
    Pascal, why there are two thing(x and y) for images? In order to make life difficult? :)
  • Pascal MARTIN
    Pascal MARTIN about 13 years
    @echophp I've edited my answer with some additional informations about that (both on the HTML side, and on the PHP side).
  • Dhamu
    Dhamu over 9 years
    input id not submitted in post...-1