Author Topic: Update via checkbox  (Read 1485 times)

0 Members and 1 Guest are viewing this topic.

Offline khnaTopic starter

  • Irregular
    • View Profile
Update via checkbox
« on: August 28, 2004, 08:20:25 AM »
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  
 
 
 

Offline morpheus.100

  • Enthusiast
    • View Profile
Update via checkbox
« Reply #1 on: August 28, 2004, 11:51:37 AM »
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.

Offline khnaTopic starter

  • Irregular
    • View Profile
Update via checkbox
« Reply #2 on: August 28, 2004, 12:03:04 PM »
Thanks for the reply,
I am new to PHP and to be honest i need a bit more help.

Quote
To udate multiple rows you need to create a loop with a counter to insert the data one row at a time.


How????
« Last Edit: August 28, 2004, 12:04:51 PM by khna »

Offline morpheus.100

  • Enthusiast
    • View Profile
Update via checkbox
« Reply #3 on: August 29, 2004, 04:52:32 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.

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.