Jump to content

Update via checkbox


Recommended Posts

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

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/1940-update-via-checkbox/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/1940-update-via-checkbox/#findComment-6313
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.