简体   繁体   English

如何将“值”字段的值放入数据库中输入类型为复选框的形式?

[英]how can i put the value of “value” field in a form where input type is checkbox from database?

i tried alot in order to fetch values from database and put it in check-box array but failed.Please help!! 我尝试了很多,以便从数据库中获取值并将其放入复选框数组中,但失败了。请帮助!

* img[] comes out to be empty all the time like no value is going into it when ever i call that part using $_POST(['img'])!!* here's my code: * img []一直都是空的,就像当我使用$ _POST(['img'])调用该部件时,没有值会变成空一样!*这是我的代码:

   echo " <h2>Select image to delete: <h2>";
   $s = mysql_query("SELECT * FROM image WHERE u_id = '$u_id'");
   $num = mysql_num_rows($s);

   if($s)
   { 
      ?>
   <form name="f1" method="post" action=""> 
      <?php
    while($row = mysql_fetch_array($s))
    { 
      ?>      
    <input type="checkbox" name="img[]" value="<?php $row['path'] ;?>" />
    <img width="100" src="<?php echo $row['path']." ";?>">
    <?php                 
    }
    ?>
       <br />
       <br />
       <input type="submit" name= "subDel" value = "Delete" />
       </form>
     <?php

    } 

What about this? 那这个呢? :) :)

<input type="checkbox" name="img[]" value="<?php $row['path'] ;?>" />

=> =>

    <input type="checkbox" name="img[]" value="<?php ECHO $row['path'] ;?>" />

Retrive post Data in PHP by using $_POST['variableName'] - no brackets, case DOES matter 通过使用$ _POST ['variableName']检索PHP中的发布数据-无括号,大小写无关紧要

In your case, $_POST['img'] is of type array . 在您的情况下,$ _POST ['img']的类型为array There is NO value for unchecked items. 未检查的项目没有价值。 If nothing checked, your post variable is empty or even undefined (didn't test it yet). 如果未进行任何检查,则您的post变量为空,甚至未定义(尚未测试)。

Access your values by 通过访问您的价值观

if (array_key_exists($index, $_POST['img']) == true) {
    // $index is checked
    $doSomething = $_POST['img'][$index];
}

暂无
暂无

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

相关问题 我怎样才能保存我的价值<input type='checkbox'>使用 Laravel 5.7 代码到 MySQL 数据库? - How can I save the value of my <input type='checkbox'> to MySQL Database with laravel 5.7 code? 如何从具有多个选择的复选框中获取输入值? - How can i get value of input from checkbox with multiple selects? 如何在输入表单字段中插入当前日期作为值 - How can i insert current date as a value in an input form field 如何将复选框开关中的值发送到 MySQL 数据库 - How can I send a value from a checkbox switch to a MySQL database 如何从数据库中获取值,并在输入字段中使用和显示它? - How can I get a Value from my Database and use and show it inside an Input Field? 如何根据其他表单字段自动从数据库中为输入字段设置值。 使用PHP? - How to set the input field with the value automatically from the database on the basis of other form field. using php? 如何将HTML输入字段中的值插入MySQL? - How can I insert the value from an HTML input field into MySQL? 当从数据库中检索的输入值为0时,表单字段为空白 - form field is blank when input value retreived from database is 0 如何使用下拉菜单中的值填充隐藏的表单字段? - How can I poupulate a hidden form field with a value from a dropdown? 使用Ajax,如何将表单中的输入值与数据库中的记录进行匹配,并获取相关的记录/行以预填表单? - Using Ajax how can I match a input value from a form to records in my database and fetch associated record/row to prefill a form?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM