mardi 5 septembre 2017

How to differentiate name in PHP

I have a code. Somehow, it only able to pick the last hidden input name field instead of the other one. I also tried use if and else but nothing is displayed. Please advise.

Without the if else cases scenario:

HTML:

            <div class="tab-label">
                        <input type="radio" id="ldktech_product_good" name="conditition" value="good" >
                        <input type="hidden" id="ldktech_product_price_good"  name="price" value="7.50">
                        <label for="ldktech_product_good">Good</label>

NOTE: Please include the charger with your iPad trade-in, or a replacement fee will be deducted from the offer

                <div class="tab-label">
                        <input type="radio" id="ldktech_product_flawless" name="conditition" value="flawless" >
                        <input type="hidden" id="ldktech_product_price_flawless"  name="price" value="10">
                        <label for="ldktech_product_flawless">Flawless</label>

PHP:

$condition = $_POST["conditition"];
$price = $_POST["price"];
echo $price;
echo "<br>";
echo $condition;

With the if else scenarios:

HTML Code:

            <div class="tab-label">
                        <input type="radio" id="ldktech_product_good" name="conditition" value="good" >
                        <input type="hidden" id="ldktech_product_price_good"  name="price-good" value="7.50">
                        <label for="ldktech_product_good">Good</label>


                <div class="tab-label">
                        <input type="radio" id="ldktech_product_flawless" name="conditition" value="flawless" >
                        <input type="hidden" id="ldktech_product_price_flawless"  name="price-flawless" value="10">
                        <label for="ldktech_product_flawless">Flawless</label>

PHP code:

$condition = $_POST["conditition"];
if($condition == "good"){
$price = $_POST["price-good"];}
else if ($condition == "flawless"){
$price = $_POST["price-flawless"];}
echo $price;
echo "<br>";
echo $condition;

Nothing work. Please advised

Aucun commentaire:

Enregistrer un commentaire