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:
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
In your case, $_POST['img'] is of type array . There is NO value for unchecked items. If nothing checked, your post variable is empty or even undefined (didn't test it yet).
Access your values by
if (array_key_exists($index, $_POST['img']) == true) {
// $index is checked
$doSomething = $_POST['img'][$index];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.