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

后端 未结 5 2184
故里飘歌
故里飘歌 2020-12-20 03:08

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.

5条回答
  •  天命终不由人
    2020-12-20 03:52

    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 , 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 becomes $_REQUEST["a_b"].

提交回复
热议问题