3

簡単な質問かもしれませんが、

画像をクリックして数字を並べ替えたい。フォームを作ってイメージフィールドを追加しようと思いました。

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

次に、これらのコードを記述します。

$sorgu='SELECT * FROM urunler';

if(isset($_POST['buyuka'])

{
    $sorgu='SELECT * FROM urunler ORDER BY uyeno DESC';
}

$sonuclar=mysql_query($sorgu);

ただし、ソートされません。イメージフィールドを追加するために送信ボタンを追加しようとすると、機能します。つまり、本当に基本的な間違いを犯したことを意味しますが、それを見つけることができません。

助けてくれてありがとう。:)

編集 --- 解決済み

実際、パスカル・マルティンは次のように述べています。

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

そのようなものでなければなりません。ありがとう :)

4

5 に答える 5

15

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"].

于 2011-04-15T20:12:21.817 に答える
0

質問を適切に読んでいる場合、画像をフォームの一部として使用しても、フォームが POST として自動的に送信されるわけではありません。実際にフォームを送信していたため、ボタンが機能しました。

ページを最初にロードするときは、表示しているフォームとは関係のない GET リクエストになります (また、ページ内に別の名前を使用した多数の他のフォームを含めることもできますが、それらは同様に送信されない限り効果がありません)。ボタンを使用して送信すると、index.php が要求され、POST パラメーターが追加されます。

onsubmit="submit-form();"入力要素に追加してみては?

于 2011-04-15T20:17:11.403 に答える
0
<form id="form1" name="form1" method="post" enctype="multipart/form-data" action="index.php">
     <input name="buyuka" type="image" src="resimler/azalt.gif" />
</form>

これを試して。

于 2011-04-15T20:17:27.013 に答える
-1
    if(isset($_POST['buyuka'])
    {
        $sorgu='SELECT * FROM urunler ORDER BY uyeno DESC';
    } 
    else 
    {
        $sorgu='SELECT * FROM urunler';
    }

Give this a try.

于 2011-04-15T20:11:57.940 に答える
-2

画像入力の場合は、ID を追加してみてください。名前はありますが、ID はありません。

交換

<input name="buyuka" type="image" src="resimler/azalt.gif" />

<input id="buyuka" name="buyuka" type="image" src="resimler/azalt.gif" />
于 2011-04-15T20:14:25.867 に答える