0

试图从下拉列表中传递值,但无法得到它。

                <tr>
                    <td>Size <br>
                    (Only applicable for T-Shirt):</td>
                    <td><select name=size>
                    <option value=N>NIL</option>
                    <option value=S>S</option>
                    <option value=M>M</option>
                    <option value=L>L</option>
                    <option value=XL>XL</option>
                    </select></td>
                </tr>

                <tr>
                    <td></td>
                    <td><a href= manageProduct.php?size=$_GET[size]>Insert</a></td>
                </tr>
4

3 回答 3

1

试试这个:(只是一个例子)。

<form action="<?php $_SERVER['PHP_SELF']?>" method="GET">
<table>
<tr>
<td nowrap>Size:
(Only applicable for T-Shirt):</td>
<td><select name="size">
<option value="N">NIL</option>
<option value="S">S</option>
<option value="M">M</option>
<option value="L">L</option>
<option value="XL">XL</option>
</select></td>
</tr>

<tr>
<td><p align="right"></p></td>
<td><input type="submit" value="Insert" />
</td>
</tr>
</table>
</form>

<?php

$size = $_GET['size'];

if($_GET['size']=="N")
{
echo "you chose NOTHING, make another choice.";
}

else {

echo "Your choice of size is: $size";
}

?>
于 2013-04-15T02:53:10.580 回答
0

html

<form action="manageProduct.php" method="POST">
    <table>
       <tr>
            <td>Size <br>
            (Only applicable for T-Shirt):</td>
            <td><select name=size>
            <option value=N>NIL</option>
            <option value=S>S</option>
            <option value=M>M</option>
            <option value=L>L</option>
            <option value=XL>XL</option>
            </select></td>
        </tr>

        <tr>
            <td></td>
            <td><input type="submit" value="Insert" /></td>
        </tr>
    </table>
</form>

PHP

$size = $_POST['size'];
于 2013-04-15T02:34:10.537 回答
0

您需要使用 GET 操作的表单,然后您可以获取变量。假设这个页面是 manageProduct.php:

        <!--GET your data from the submitted form OR do something depending on what size returns in the url-->
    <?php

    if($_GET['size']=="SIZE"){ echo whatever or do whatever}
    ?>


        <td><a href

="manageProduct.php?size=<? echo $_GET['size'] ?>">Whatever you're trying to do</a></td>

        <form id="form" method="get" action="manageProduct.php">
            <tr>
                            <td>Size <br>
                            (Only applicable for T-Shirt):</td>
                            <td><select name="size">
                            <option value="N">NIL</option>
                            <option value="S">S</option>
                            <option value="M">M</option>
                            <option value="L">L</option>
                            <option value="XL">XL</option>
                            </select></td>
                        </tr>

                            <tr>
                                <td></td>
    <td><input type="submit" name="Submit" value="Insert" /></td>
    <br />
    </form>

                            </tr>
于 2013-04-15T02:32:58.117 回答