jaminxz Posted February 23, 2009 Share Posted February 23, 2009 Hi everyone, i'm trying to create a page that displays multiple records and a checkbox for each row. When the submit buton is clicked, every record that has its checkbox clicked should have its status fields updated to '0'. I have been following this tutorial http://www.phpfreaks.com/tutorial/working-with-checkboxes-and-a-database/page4 (and trying to tailor it slightly to my needs) but with no joy. My problem is that the value of the checkbox (whcih should be ID) is not getting passed through for some reason - i have been using var_dump to tell this. I'm sure its a rookie mistake i'm making but i've spent hours on this and cant get it to work. Please can comeone cast their eye over it and hopefully help me out? many thanks in advance, Jaminxz. The checkbox code: <td colspan="2" align="left"><span><input type="checkbox" name="Update[]" value="<?php $row_query4['ID']; ?>" /></span></td> /*note $row_query4['ID'] is definitiely pulling through the id The main code block: $updated = FALSE; //If IS_PostBack then database is to be updated if(isset($_POST['Update'])){ $Update = $_POST['Update']; //make sure every ID in the array is an integer to avoid SQL injection! array_map('intval',$Update); $Update = implode(',',$Update); mysql_query("UPDATE Ad_item SET STATUS=0 WHERE ID IN ($Update)") or trigger_error(mysql_error(),E_USER_ERROR); $updated=TRUE; } Output from var_dump------------- array 0 => string '' (length=0) 1 => string '' (length=0) 2 => string '' (length=0) /* It knows how many checkboxes have been checked, but just not the value?? */ Quote Link to comment https://forums.phpfreaks.com/topic/146499-updating-multiple-rows-through-checkboxes/ Share on other sites More sharing options...
wrathican Posted February 23, 2009 Share Posted February 23, 2009 you need to loop through each updater <?php for($i = 0; $i < count($Update); $i++){ //run your update code } ?> Quote Link to comment https://forums.phpfreaks.com/topic/146499-updating-multiple-rows-through-checkboxes/#findComment-769103 Share on other sites More sharing options...
sasa Posted February 23, 2009 Share Posted February 23, 2009 change value="<?php $row_query4['ID']; ?>" to value="<?php echo $row_query4['ID']; ?>" Quote Link to comment https://forums.phpfreaks.com/topic/146499-updating-multiple-rows-through-checkboxes/#findComment-769113 Share on other sites More sharing options...
wrathican Posted February 23, 2009 Share Posted February 23, 2009 change value="<?php $row_query4['ID']; ?>" to value="<?php echo $row_query4['ID']; ?>" ahh yes. That is a better solution Quote Link to comment https://forums.phpfreaks.com/topic/146499-updating-multiple-rows-through-checkboxes/#findComment-769119 Share on other sites More sharing options...
jaminxz Posted February 23, 2009 Author Share Posted February 23, 2009 absolute legend! thanks so much, I knew I'd be doing something daft, I think I was working on the logic that if i didn't need it printing in html, i didn't need the echo statement, d'oh! Quote Link to comment https://forums.phpfreaks.com/topic/146499-updating-multiple-rows-through-checkboxes/#findComment-769139 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.