Jump to content


Photo

Update via checkbox


  • Please log in to reply
3 replies to this topic

#1 khna

khna
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 28 August 2004 - 12:20 PM

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




#2 morpheus.100

morpheus.100
  • Members
  • PipPipPip
  • Advanced Member
  • 145 posts

Posted 28 August 2004 - 03:51 PM

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.

#3 khna

khna
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 28 August 2004 - 04:03 PM

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????

#4 morpheus.100

morpheus.100
  • Members
  • PipPipPip
  • Advanced Member
  • 145 posts

Posted 29 August 2004 - 08:52 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users