Avatar of pc-buddy
pc-buddy

asked on 

PHP foreach DB query

Hi,

I have a long list of tick boxes where i select multipul items, i then have a foreach once the form is submited where i'm trying to do a datebase query, but it dopesnt work I can see the id'd being passed over but the query will only run once, what is the best practice to do this.

<input name='selectedchild[]' type='checkbox' value='{$row['id']}'>
           <input name='selectedchild[]' type='checkbox' value='{$row['id']}'>
           <input name='selectedchild[]' type='checkbox' value='{$row['id']}'>

Open in new window


foreach($_POST['selectedchild'] as $id)
{
		mysql_query("INSERT INTO outings (child_id) VALUES(".$id.")");
		  
		$query = "select email,email2 FROM child WHERE id = ".$id."";
		$result = mysql_query($query );

		$email=mysql_result($result ,$i,'email');
		$email2=mysql_result($result ,$i,'email2');

		$mail->Addbcc($email);
		if ($email2 != ""){
		$mail->Addbcc($email2);
		
		}
}

Open in new window


Thanks Simon
PHPWeb Development

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon