sicKo Posted April 27, 2009 Share Posted April 27, 2009 I'm trying to delete data from database by ticking the checkbox and press the delete button... but it doesn't deems to work.. help pleasee.. <?php $con = mysql_connect("localhost","root",""); mysql_select_db("test2",$con); $sql = "select * from member"; $result = mysql_query($sql,$con); ?> <form action = "deletetest.php" method = "POST"> <?php while($row = mysql_fetch_assoc($result)) { ?> <tr><td><input type = "checkbox" name = "deletebox" value="<?php echo $row['member_ID']; ?>"></td> <td><?php echo $row['member_ID']; ?></td> <td><?php echo $row['FirstName']; ?></td> </tr><br/> <?php } ?> <tr><td><input type = "submit" name = "submit" value = "delete"></td></tr> </form> <?php if($_POST['submit'] == 'submit') { foreach($_POST['deletebox'] as $key) { $sql2 = "delete from member where member_ID = '$key'"; mysql_query($sql2,$con); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/155780-solved-delete-function-with-checkbox/ Share on other sites More sharing options...
mikesta707 Posted April 27, 2009 Share Posted April 27, 2009 change this <tr><td><input type = "checkbox" name = "deletebox" value="<?php echo $row['member_ID']; ?>"></td> to this <tr><td><input type = "checkbox" name = "deletebox[]" value="<?php echo $row['member_ID']; ?>"></td> and it should work (I think, someone correct me if im wrong ). Hope that helps! Quote Link to comment https://forums.phpfreaks.com/topic/155780-solved-delete-function-with-checkbox/#findComment-820034 Share on other sites More sharing options...
sicKo Posted April 27, 2009 Author Share Posted April 27, 2009 tried that but still not working... Quote Link to comment https://forums.phpfreaks.com/topic/155780-solved-delete-function-with-checkbox/#findComment-820036 Share on other sites More sharing options...
PFMaBiSmAd Posted April 27, 2009 Share Posted April 27, 2009 The value of your submit button in the form is not the same value your php code is testing it for. Quote Link to comment https://forums.phpfreaks.com/topic/155780-solved-delete-function-with-checkbox/#findComment-820037 Share on other sites More sharing options...
mikesta707 Posted April 27, 2009 Share Posted April 27, 2009 ah i think i see the problem <tr><td><input type = "submit" name = "submit" value = "delete"></td></tr> </form> <?php if($_POST['submit'] == 'submit') the value of the submit button (named submit) is delete, and you are testing to see if its value is submit change the above to <tr><td><input type = "submit" name = "submit" value = "submit"></td></tr> </form> <?php if($_POST['submit'] == 'submit') and it should work hope that helped EDIT: Dam too late haha. Quote Link to comment https://forums.phpfreaks.com/topic/155780-solved-delete-function-with-checkbox/#findComment-820039 Share on other sites More sharing options...
sicKo Posted April 27, 2009 Author Share Posted April 27, 2009 yeah.. problem solved.. stupid mistake, huh?... thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/155780-solved-delete-function-with-checkbox/#findComment-820051 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.