php - 在 $_POST 中找不到输入类型=图像值

标签 php mysql forms imagefield

好吧,这可能是一个简单的问题,但是:

我想通过单击图像对数字进行排序。我以为我制作了一个表单并添加了一个图像字段。

<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);

但是它没有排序。当我尝试添加提交按钮以添加图像字段时,它起作用了。所以这意味着我犯了一个非常基本的错误,但我找不到它。

谢谢你的帮助。 :)

编辑 --- 已解决

正如 Pascal Martin 所说:

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

一定是这样的。谢谢:)

最佳答案

只需使用 var_dump() 查看 $_POST 中的内容:

var_dump($_POST);

您会看到,当您使用 <input type="image"> 提交表单时,你得到:

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


所以,没有 $_POST['buyuka'] -- 相反,有:

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

这意味着您的代码应该看起来像这样 (不测试不存在的 buyuka 条目,而是测试两个 _x_y -- 我想测试其中一个就足够了):

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



在评论后编辑:我不知道为什么它是那样的——但是有一个.x和一个 .y是它在 HTML 标准中的定义方式。

如果你看一下Forms in HTML documents ,然后向下滚动一点,您将能够阅读:

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.

在 PHP 中,参数名称中的点自动替换为和 unerscore。
所以:

  • name.x变成 name_x
  • name.y变成 name_y

作为最后一条语句的来源,您可以阅读变量 From External Sources - HTML Forms (GET and POST) (引用):

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

关于php - 在 $_POST 中找不到输入类型=图像值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5681837/

相关文章:

php - 形成新闻副本

php - 使用 PHP 和 NuSOAP 通过 HTTPS 发出 SOAP 请求

php登录系统显示空白页

javascript - 如何将变量从按钮的 onclick 传递到 javascript 代码?

javascript - 更新 JavaScript 中的表单字段

php - utf8字符串长度

php - 如何返回给定产品的最高分图像?

php mysql where 语句 with AND 返回 true 即使第二个条件为 false

MySQL 触发器内的日期差异检查

javascript - html 和 javascript 表单不工作