insert span values in database with PHP Prepared S

2019-09-01 18:35发布

I have a contact form where I have some checkboxes. After the user submits the form I want to get their entries in the database. I can do this properly, but today I wanted to change my form to be responsive. I changed my simple checkboxes to span tags, but now I can not get the values in the database. It did not give me any error but also did not show anything in the database.

<html>
  <body>
    <form action="" method="POST" >
<section>
  <div class="wrapper-checkbox">

    <div class="checkbox">
      <div class="text">
        <span name="check1" value="rent">rent</span>
      </div>
    </div>

    <div class="checkbox">
      <div class="text"> 
        <span   name="check2" value="buy">buy</span>
      
      </div>
    </div>
  </div>
</section>
    <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src="js-checkbox/index.js"></script>
      </form>

<?php
$check1 = !empty($_POST['check1']) ? $_POST['check1'] : '';
$check2 = !empty($_POST['check2']) ? $_POST['check2'] : '';
if ($stmt = mysqli_prepare($connect, "INSERT INTO $db_table VALUES (?, ?)"))
{
mysqli_stmt_bind_param($stmt, "ss",$check1,$check2);
?>
   </body>
 </html>

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-09-01 19:00

You can also done it by using hidden field within a form tag EX-

<input type="hidden" name="check1" value="rent">

and access the value via

<?php
    $check1 = !empty($_POST['check1']) ? $_POST['check1'] : '';
    $check2 = !empty($_POST['check2']) ? $_POST['check2'] : '';
 ?>
查看更多
登录 后发表回答