khna Posted August 28, 2004 Share Posted August 28, 2004 Hi all, I am looking for a way to batch update checkbox fields values in Mysql database. I have a repeat region with checkboxes and am trying to update checkbox fields in MySQL database. Something like Update command in ASP/Vbscript. I have tried: <?php $ParamID = "1"; if (isset($HTTP_GET_VARS['checkbox'])) { $ParamID = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['checkbox'] : addslashes($HTTP_GET_VARS['checkbox']); } $result=mysql_query("UPDATE tbl_model_name SET fld_select = 1 WHERE ID = $ParamPicID") or die ("Invalid Query"); //header ("Location: test_selected.php"); ?> First i am not sure if the code is 100% correct. 2nd which i am pretty sure it seems like the checkbox values are not being passed from the previous page. How do i pass or force to pass the checkbox values in the repeated region to make this code work? I thank you in advance. Best Regards Khna Quote Link to comment https://forums.phpfreaks.com/topic/1940-update-via-checkbox/ Share on other sites More sharing options...
morpheus.100 Posted August 28, 2004 Share Posted August 28, 2004 This insert will only execute a single time. To udate multiple rows you need to create a loop with a counter to insert the data one row at a time. Quote Link to comment https://forums.phpfreaks.com/topic/1940-update-via-checkbox/#findComment-6306 Share on other sites More sharing options...
khna Posted August 28, 2004 Author Share Posted August 28, 2004 Thanks for the reply, I am new to PHP and to be honest i need a bit more help. To udate multiple rows you need to create a loop with a counter to insert the data one row at a time. How???? Quote Link to comment https://forums.phpfreaks.com/topic/1940-update-via-checkbox/#findComment-6308 Share on other sites More sharing options...
morpheus.100 Posted August 29, 2004 Share Posted August 29, 2004 Ok you have say 30 checkboxes all needing to input data to the same row. Each checkbox in your for needs a count identifier. Create this by making a loop. Firstly I would have a selector so I can select how many for fields i need and create the form dynamically. so <?php for($i=0; $i <= $number; $i++){ ?> <input type="checkbox" name="element_name[<?php echo $i ?>]"> <?php } ?> This will repeat the <input> line the amount of times you define in $number. The php echo $i line will add a count value to the field to identify for the sqlupdate. Now you need a similar function for the insert. You should now be able to play around to achieve a similar cycle to insert the data. Quote Link to comment https://forums.phpfreaks.com/topic/1940-update-via-checkbox/#findComment-6313 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.