Link to home
Start Free TrialLog in
Avatar of Luey
LueyFlag for United States of America

asked on

write multiple records

Hello I have multiple check boxes within a form.  I need to write an individual record for each checkbox that is checked and place its value in the record.  I am not looking for someone to write the code. I just cannot wrap my head around an idea on how to do it.  Any ideas? (using php mysql)  Thanks

<label><input name="1" id="1" type="checkbox" value="1"></label>
<label><input name="2" id="2" type="checkbox" value="2"></label>
<label><input name="3" id="3" type="checkbox" value="3"></label>
<label><input name="4" id="4" type="checkbox" value="4"></label>

Open in new window

Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Your 'name' and 'id' attributes should not be a number.  They can contain a number after a letter.  PHP and javascript will not like names that are just a number, they won't be valid in PHP.

When your form is submitted, all the boxes that are check will be sent to your PHP script in the form of 'name=value'.  If you use the GET method, you will find them in your PHP script as variables with $_GET['name'].  If it is POST method, it will be $_POST['name'].

More info and examples of GET and POST variables here: http://www.php.net/manual/en/reserved.variables.php
Avatar of Luey

ASKER

I was using the numbers as examples.  Their values and names are filled from data.  I am not new to this I know all that you have said.  What I am trying to do is write and individual file for every check box that is checked.  Not sure it is possible.
Just want to know if it is and how to pursue it.  Not one record but individual records for each checked check box.
Sorry, but it's distracting when you post things that aren't right for your example.  It tends to make people think you know less about what you are doing.

Files?  Records?  Are you using a database or do you want to actually write files to disk?  In any case, you can just create a loop that goes thru the submitted fields and do either one or both.  The only thing 'special' about checkboxes is that the ones that aren't checked are not submitted.
Avatar of Luey

ASKER

Yea yea it is late and I am tired.  I want to write an individual record for each check box that is checked in mysql database.

I know I need to loop but I just can't see how to get each check box in a different record.  
Here is some code I have been using to loop through a recordset.  But I do not know how to loop through the check boxes.  This code has nothing to do with what I am working on.  I just want to know how to loop through the check boxes i guess?

 do {
  $member_id = $row_members['mem_member_id'];
  $insertSQL = sprintf("INSERT INTO email_jobs (job_member_id, job_email_id) VALUES (%s, %s)",
                       GetSQLValueString($member_id, "int"),
					   GetSQLValueString($_POST['email_id'], "int"));
    
 mysql_select_db($database_hootdata, $hootdata);
  $Result1 = mysql_query($insertSQL, $hootdata) or die(mysql_error());
  } while ($row_members = mysql_fetch_assoc($members)); 

Open in new window

Avatar of Luey

ASKER

I think I have it figured out now.  I will post the code on friday if I can make it work.  Any suggestions would be appreciated. Thanks
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Luey

ASKER

thanks
Luey: Please see the grading guidelines here:
https://www.experts-exchange.com/help/viewHelpPage.jsp?helpPageID=26

Please explain what you were expecting and why you marked the grade down, thanks. ~Ray