简体   繁体   English

将范围标签中的值插入SQL数据库

[英]Inserting value from span tag into SQL database

I have a form filled with 24 checkboxes that a user fills in, underneath these checkboxes I have 2 span tags. 我有一个填写有24个复选框的表单,用户可以在其中选中2个span标签。 One counts how many are checked, and the other displays what percentage it is. 一个计算要检查的数量,另一个显示要检查的百分比。 When I submit this form, I get the following error: Undefined index: #countcheckboxes in D:\\inetpub\\wwwroot\\SMT_24_Point_Check\\newAudit.php on line 33 提交此表单时,出现以下错误:未定义索引:第33行的D:\\ inetpub \\ wwwroot \\ SMT_24_Point_Check \\ newAudit.php中的#countcheckboxes

These are my span tags at the bottom of the form... 这些是表格底部的我的span标签...

 <div class="count-checkboxes-wrapper">
 Total score: <span id="count-checked-checkboxes" 
 name="countcheckboxes">0</span> out of 24 checked
 </div><br>
 <!-- button to show div below -->
 <input type="button" value="Show Audit Score" onclick=showDiv()>
 <!--div showing total audit score as percentage-->
 <div id="percentDiv"; style="display:none;" class="percentage-checkboxes- 
 wrapper">
 Audit Result:<span id="percentage-checked-checkboxes" 
 name="percentagecheckboxes"> 0</span> %
 </div>

On the newAudit.php page, this is the post tags I have for those 2 span tags... 在newAudit.php页面上,这是我为这2个span标签设置的post标签...

$totalChecked = $_POST['countcheckboxes'];
$auditScore = $_POST['percentagecheckboxes'];

The out put from the checkboxes displays: Total score: 2 out of 24 checked And after 'show audit score' is clicked, it says 'Audit result: 8%. 复选框的输出显示:总分:24个已检查中的2个。单击“显示审核分数”后,显示“审核结果:8%”。 I need the values of 2 and 8% to be inserted into the database. 我需要将2和8%的值插入数据库。

There are lot of options for you to get the values rather that using meaningless name attribute over span . 有很多选项可让您获取值,而不是在span使用无意义的name属性。

  1. Use a data-count attribute over both divs ie, count-checked-checkboxes and percentagecheckboxes . 在两个div上都使用data-count属性,即count-checked-checkboxespercentagecheckboxes With the same function, that update the counts, do update the data-attributes. 使用与更新计数相同的功能,可以更新数据属性。 At the time of data post, get those values by let checkCount = $('#count-checked-checkboxes').attr('data-count'); 在数据发布时,通过let checkCount = $('#count-checked-checkboxes').attr('data-count');获得这些值let checkCount = $('#count-checked-checkboxes').attr('data-count'); and so on. 等等。
  2. Use a hidden input box in the place of span, and update the values of those box with the same update function, and get the values by using let checkCount = $('#count-checked-checkboxes').val() and so on. 在跨度位置使用一个隐藏的输入框,并使用相同的更新函数更新这些框的值,并通过使用let checkCount = $('#count-checked-checkboxes').val()来获取值let checkCount = $('#count-checked-checkboxes').val()上。
  3. ( Not recommended ) use the text value of those span by using let checkCount = $('#count-checked-checkboxes').text() and so on. (不建议)通过使用let checkCount = $('#count-checked-checkboxes').text()等来使用跨度的文本值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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