duandai0373 2018-08-12 11:36
浏览 68

php中的POST无线电类型值[重复]

This question already has an answer here:

I am using an order form on my website and the client has multiple option of what type of graphics that they require but I'm not sure how I read in the value they selected for the multiple choice option.

Here is the .html code for the order form:

    <section id="Order">
      <div class="container">
        <h2>Order</h2>
        <form action="order.php" method="post" id="usrform">
          <fieldset>
            <legend>What type of graphics would you like to purchase?    </legend>
              <p>
                  <input type="radio" name="size" id="item_1"     value="Social_Media">
                    <label for="item_1">Social Media</label>
                  </p>
                  <p>
                      <input type="radio" name="size" id="item_2" value="Twitch_Package">
                      <label for="item_2">Twitch Package</label>
                    </p>
                    <p>
                        <input type="radio" name="size" id="item_3" value="Mascot_Logo">
                        <label for="item_3">Macot Logo</label>
                      </p>
                      <p>
                          <input type="radio" name="size" id="item_4" value="2D_Logo">
                          <label for="item_3">2D Logo</label>
                        </p>
                        <p>
                            <input type="radio" name="size" id="item_5" value="3D_logo">
                            <label for="item_3">3D Logo</label>
                          </p>
                          <p>
                              <input type="radio" name="size" id="item_6" value="other">
                              <label for="item_3">Other</label>
                            </p>
                      </fieldset> </br> </br>
                      Enter email: </br>
                      <input type = "email" name = "userEmail" autocomplete="on" required> </br> </br>
                      Enter details </br>
                      <textarea rows="4" cols="50" name="comment" form="usrform"></textarea> </br> </br>
                      <input type = "submit" name = "submit" value = "SUBMIT" >
                    </form>

      </div>
        </section>

This is the .php code below from the order.php page:

    <?php

    $host="localhost";
    $user="";
    $password="";
    $dbname="id321208_clients";
    $cxn=mysqli_connect($host,$user,$password,$dbname) or die("Couldn't connect to the server");

    $type=$_POST['size'];
    $email=$_POST['userEmail'];
    $details=$_POST['comment'];

    $query="INSERT INTO usersDetails (size, userEmail, comment) VALUES     ('$type', '$email', '$details')";

    if(mysqli_query($cxn,$query)){
            echo"I have recieved your email! I will contact you as soon as I     can.";
        }else{
            echo"Error- ".mysqli_error($cxn);
        }

    echo '<a href="Order.html"> Click to return</a>';

    mysqli_close($cxn);
    ?>
</div>
  • 写回答

1条回答 默认 最新

  • duanao4729 2018-08-12 11:46
    关注

    first of all, your radio button is overwritten each time you declared it, since you are using the same name, please set them using this code:

    <section id="Order">
          <div class="container">
            <h2>Order</h2>
            <form action="order.php" method="post" id="usrform">
              <fieldset>
                <legend>What type of graphics would you like to purchase?    </legend>
                  <p>
                      <input type="checkbox" name="size[]" id="item_1"     value="Social_Media">
                        <label for="item_1">Social Media</label>
                      </p>
                      <p>
                          <input type="checkbox" name="size[]" id="item_2" value="Twitch_Package">
                          <label for="item_2">Twitch Package</label>
                        </p>
                        <p>
                            <input type="checkbox" name="size[]" id="item_3" value="Mascot_Logo">
                            <label for="item_3">Macot Logo</label>
                          </p>
                          <p>
                              <input type="checkbox" name="size[]" id="item_4" value="2D_Logo">
                              <label for="item_3">2D Logo</label>
                            </p>
                            <p>
                                <input type="checkbox" name="size[]" id="item_5" value="3D_logo">
                                <label for="item_3">3D Logo</label>
                              </p>
                              <p>
                                  <input type="checkbox" name="size[]" id="item_6" value="other">
                                  <label for="item_3">Other</label>
                                </p>
                          </fieldset> </br> </br>
                          Enter email: </br>
                          <input type = "email" name = "userEmail" autocomplete="on" required> </br> </br>
                          Enter details </br>
                          <textarea rows="4" cols="50" name="comment" form="usrform"></textarea> </br> </br>
                          <input type = "submit" name = "submit" value = "SUBMIT" >
                        </form>
    
          </div>
            </section>
    

    After that, you can access them as array using:

    $type=$_POST['size'];
    foreach($type as $selectedType){
       echo $selectedType."<br/>";
    }
    

    You can do whatever you need now with them.

    评论

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备