[英]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.