简体   繁体   中英

Getting the value of input tag in php

I am trying to get the value of my input upon a click of the button. I am able to get the value of text box but not for drop down list and number box (input type=number).

How should I go about doing it?

Below is my code:

          <div class=accountMain>
            <div align=left>
            <table>
                <tr>
                    <td>Product Code:</td>
                    <td>EX00001</td>
                </tr>
                <tr>
                    <td>Product Name:</td>
                    <td><input type=text name=productName value=$productName></td>
                </tr>

                <tr>
                    <td>Description:</td>
                    <td><input type=text name=productDesc value=$productDesc></td>
                </tr>

                <tr>
                    <td>Price: SGD$</td>
                    <td><input type=text name=unitPrice value=$unitPrice></td>
                </tr>

                <tr>
                    <td>Quantity Available:</td>
                    <td><input type=text name=qty value=$qty></td>
                </tr>

                <tr>
                    <td>Size <br>
                    (Only applicable for T-Shirt):</td>
                    <td><select>
                    <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>Product Image:</td>
                    <td><input type=file name=imgfile></td>
                </tr>

                <tr>
                    <td>Category: Exclusive</td>
                </tr>

                <tr>
                    <td></td>
                    <td><input type=submit name=insert value=Insert></td>
                </tr>

            </table>
            </div>

    </td>
    </tr>


    </div>



 echo("<tr><td></td>
                        <td></td>
                        <td><font style=title><b>In Stock : ".$row["qty"]."</b></br></br></br></br>
                        <b><form>Purchase Qty : <input type=number name=qty min=1 max=5></form></b></br></br>
                        </br></font></td>

                        </tr>");

                echo("<tr><td></td>
                        <td></td>
                        <td><a href=shoppingbag.php><img src=images/addToCartBtn.png width=150></a></td></tr>");

您的<select>需要name属性

Change the following:

<select>
    <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>

To:

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

And get it using:

<?php $_POST["size"]; ?>

Since this is also marked under PHP, I presume you want to send these values to a PHP page?

If so, unless you are submitting the values dynamically (through script), you'll want to wrap the input and select elements in <form> opening and closing tags. Then you can set the method attribute ( post,put,get,delete ) and the action attribute ( the path to the PHP page to process the values ).

<form method="post" action="path-to/my-php-page.php">
...
</form>

HINT: The way your HTML is structured, you may want to wrap the whole of the innermost table with the form tag.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM