Jump to content

Posting selected records from html table...how?


dwest

Recommended Posts

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!
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

Sorry, I'm confused.

Example:

checkbox  |  Name  |  Address |  City
Checkbox    Ted      street1      New York
Checkbox    Bob      street2      Las Vegas
Checkbox    Will      street3      London

Say 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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.