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 :)
Give this a try.
Just use
var_dump()
to see what's in$_POST
:And you'll see that, when your form is submitted using the
<input type="image">
, you get :So, there is no
$_POST['buyuka']
-- instead, there are :$_POST['buyuka_x']
$_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) :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 :
In PHP, the dots in parameters names are automatically replaced by and unerscore.
So :
name.x
becomesname_x
name.y
becomesname_y
As a source for that last statement, you can read Variables From External Sources - HTML Forms (GET and POST) (quoting) :
For the image input try adding an id. You have a name, but no id.
Replace
with
If I am reading the question properly, then having the image as part of the form does not automatically submit the form as POST. The button made it work because you were actually submitting the form.
When you initially load the page, it will be a GET request with no relation to the form that you are showing us (and you could have numerous other forms in the page using different names, that would similarly have no effect unless submitted themselves). When you submit using the button, it requests index.php and adds the POST parameters.
Try adding
onsubmit="submit-form();"
to the input element?try this.