I am having multi record delete problem. It shows an error about foreach loop.

  <?php if(isset($_REQUEST['action'])&&$_REQUEST['action']=="delete") 
          {

             $value=$_REQUEST['check'];
            foreach($value as $ids)
            {

  $dquery="SELECT songname FROM songs WHERE id='$ids'";
  $dresult=mysql_query($dquery);
  $drow=mysql_fetch_array($dresult);
  $songtodel=$drow['songname'];
  $path2="../upload/$songtodel";
  if(is_file("../upload/$songtodel"))
  unlink($path2);
  $mdquery="DELETE FROM songs WHERE id='$ids'"; 
  mysql_query($mdquery); 

            }

          } 

What kind of error does it show? I think you should also post the code for your form.

QWarning: Invalid argument supplied for foreach() in D:\wamp\www\greenmusic\admin\sec.php on line 409

<td width="4%"><input type="checkbox" name="master" onClick="checkedAll('adminsform')" value=""/></td>

The argument you pass to the foreach should be an array. A question, do you have checkboxes in your form called check? If you have, then, instead of

<input type = "checkbox" name = "check"/>

you should write

<input type = "checkbox" name = "check[]"/>

Here is an example of what I mean, assuming your form is below

<form method = "post" action = "your_server_script.php">
	<input type = "checkbox" name = "check[]" value = "A"/>
	<input type = "checkbox" name = "check[]" value = "B"/>
	<input type = "checkbox" name = "check[]" value = "C"/>
	<input type = "checkbox" name = "check[]" value = "D"/>
	<input type = "checkbox" name = "check[]" value = "E"/>
	<input type = "submit" name = "but" value = "DELETE"/>
</form>

now you can write your foreach like this

<?php
	if(isset($_POST['but']))//If the user has clicked the submit button
	{
		$check = $_POST['check'];
		
		foreach($check as $ck)
		{
			//Your query here
		}
	}

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.