dwest Posted January 20, 2007 Share Posted January 20, 2007 Hi,What is the best way to accomplish this?I have an html table with 5 columns, the first of which contains a checkbox for each record, the rest containing data for each record.I want to select specific records using the checkboxes and copy those records to a database table by posting the data to a processing page.I understand that would require an SQL insert to get the data into the database.My question then is how to code the gathering of the selected records and post them to the processing page?I'd like to avoid Javascript if I can and keep it all PHP.Thanks! Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted January 20, 2007 Share Posted January 20, 2007 Wherever the form action is pointing to, on that page you would just grab the values of the checkboxes with $_POST.[code]$email = $_POST['email'];$blah = $_POST['blah'];mysql_query("INSERT INTO table_name (email, blah) VALUES ('$email', '$blah')")or die(mysql_error());[/code]Although you might have to get a little more complex with checkboxes and may want to store the values in an array. Also you need to find a way to check which ones they marked...which is where the array would come in handy. Quote Link to comment Share on other sites More sharing options...
linuxdream Posted January 20, 2007 Share Posted January 20, 2007 David??? Is that you?? Quote Link to comment Share on other sites More sharing options...
Crimpage Posted January 20, 2007 Share Posted January 20, 2007 The Checkbox would have the value of the record_id and the name of id[] which tells php that all the checked options go into the one array.They would look like: <INPUT type='checkbox' name='id[]' value='1'> or whatever the value is.That will then go to $_POST['id'] when the form is submitted and you can iterate through the array and move the records that were selected.Cheers,Dave Quote Link to comment Share on other sites More sharing options...
dwest Posted January 20, 2007 Author Share Posted January 20, 2007 Sorry, I'm confused.Example:checkbox | Name | Address | CityCheckbox Ted street1 New YorkCheckbox Bob street2 Las VegasCheckbox Will street3 LondonSay that Ted and Will are selected.I need to copy the entire record for Ted and Will to another database.So how do all the columns of data get captures for posting??Thanks! Quote Link to comment Share on other sites More sharing options...
linuxdream Posted January 20, 2007 Share Posted January 20, 2007 So each checkbox would be name="id[]" value="recordid"Then in your processing script...[code]foreach($_POST['id'] as $selected){ $db->query('INSERT INTO table SELECT * FROM oldtable WHERE id = $selected');}[/code]Something like that. Quote Link to comment Share on other sites More sharing options...
dwest Posted January 20, 2007 Author Share Posted January 20, 2007 Ahhh! I see. Sorry for the blind eye.Thanks much! Quote Link to comment 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.