在$ _POST中找不到输入类型=图片值 [英] Can't find an input type=image value in $_POST
问题描述
好的可能是简单的问题,但:
我想通过点击图片来排序数字。
< form id =form1name =form1method我认为我创建了一个表单并添加了一个imagefield。 =postaction =index.php>
< input name =buyukatype =imagesrc =resimler / azalt.gif/>
< / form>
然后我会写这些代码。
$ sorgu ='SELECT * FROM urunler';
if(isset($ _ POST ['buyuka'])
{
$ sorgu ='SELECT * FROM urunler ORDER BY uyeno DESC';
}
$ sonuclar = mysql_query($ sorgu);
当我尝试添加提交按钮为了添加imagefield,它的工作原理。所以这意味着我犯了一个非常基本的错误,但我无法找到它。
:)
编辑---已解决
实际上,正如帕斯卡尔马丁说的那样:
p> if(isset($ _ POST ['buyuka_x'],$ _POST ['buyuka_y']))
{
$ sorgu ='选择*从urunler ORDER BY uyeno DESC';
}
它必须是这样的。感谢:)
noreferrer> var_dump()
查看 $ _ POST中的内容
: var_dump($ _ POST);
你会发现,当你的表单使用< ;输入类型=图像>
,你会得到:
$ p $ array
' buyuka_x'=>字符串'0'(长度= 1)
'buyuka_y'=>字符串'0'(长度= 1)
所以,没有 $ b
$ _ POST ['buyuka_y']
这意味着你的代码看起来应该像这样(不是测试不存在的 buyuka code>条目,并测试两个
: _x
和 _y
- 我想测试其中一个这些应该足够了)
if(isset($ _ POST ['buyuka_x'],$ _POST ['' buyuka_y']))
{
$ sorgu ='选择*来自urunler ORDER BY uyeno DESC';
}
< hr>
在评论之后进行编辑:我不知道为什么 那样 - 但是有一个 .x
和 .y
是HTML标准中的定义。
如果您查看 HTML文档中的表单,然后向下滚动一下,就可以阅读:
当指针设备用于
点击图片,表单是
提交的,点击坐标
传递给服务器。
x值
是以图像
左边的像素和图像顶部的像素
的y值来度量的。
提交的数据包括
name.x = x-value
和name.y = y-value
其中name是名称
属性的值,x值和y值是
x和y坐标值,$ b $ b 。
在PHP中,参数名称中的点自动被替换为和unerscore。
So:
name.x
变成 name_x
name.y
变成 name_y
作为最后一条语句的源代码,您可以读取变量 来自外部来源 - HTML表单(GET和POST) (引用):
变量名称中的点和空格是
转换为下划线。
对于
示例< input name =ab/>
变为
$ _ REQUEST [a_b ]
。
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 :)
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 includesname.x=x-value
andname.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
becomesname_x
- and
name.y
becomesname_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"]
.
这篇关于在$ _POST中找不到输入类型=图片值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!