English 中文(简体)
2. 掌握PHP的名称和价值
原标题:Get name and value with PHP
  • 时间:2011-05-16 22:51:00
  •  标签:
  • php
  • arrays

我有这样的简单形式:

<>光度>:

<input type="checkbox" name="product[]" value="20$" /> book
<input type="checkbox" name="product[]" value="30$" /> plane

http://www.un.org/spanish/ecosoc


$product = $_POST[ product ];
foreach($product as $value) {
    echo $value;
}

Note:
The user can choose one or two ... products.

Question:
I want to know if there is a solution to get the name too, like adding an ID class or something ..

Basly 页: 1 属性,因为我没有用表格寄给它。

最佳回答

将缺失的信息添加到贵处的参数:

<input type="checkbox" name="product[book]" value="20$" /> book
<input type="checkbox" name="product[plane]" value="30$" /> plane

You can iterate over it like this:

foreach ($_POST[ product ] as $name => $value) {
    // ...
}
问题回答

你们可以使用难以捉摸的办法,但在这种情况下,你似乎将价格从客户转至服务器。 这可能使人们得以欺诈。 他们只能用一点的黑客来支付另一个(低价)的价格。 如果你只是寄出书,重新计算服务器的价格,那就是一个问题。

如果你选择这条道路,你就只能把产品(书)放在价值上:

<input type="checkbox" id="book" name="product[]" value="book" />
<label for="book">book</label>
<input type="checkbox" id="plane" name="product[]" value="plane" />
<label for="plane">plane</label>




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签