Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Ikey Onwubuemeli
PLUS
Ikey Onwubuemeli
Courses Plus Student 410 Points

DELETE MULTIPLE FIELDs USING CHECKBOX. NOT DELETING FROM DB. WHAT AM I CODING WRONG?!

<tr> <th><input type="submit" name="delete" id="delete" value="DELETE"></th> <th>name</th> <th>comp</th> </tr>

<?php $query=mysql_query("SELECT * FROM riv"); $count=mysql_num_rows($query); while($riv=mysql_fetch_assoc($query)) {

   echo"<tr>";
   echo"<td><input type=checkbox name=checkbox[] id=checkbox[] value=<?php echo $riv[id]; ?></td>";
   echo"<td>$riv[name]</td>";
   echo"<td>$riv[comp]</td>";
   echo"</tr>";

}
?>

<?php // Check if delete button active, start this if(isset($_POST['delete'])){ for($i=0;$i<$count;$i++){ if(isset($_POST['checkbox[]'])){ $del_id = $id[$i]; echo $del_id; $sql = "DELETE FROM riv WHERE id='$del_id'"; $result = mysql_query($sql);} } }
?>