Jump to content

A point in the right direction


spires

Recommended Posts

Hi,

Can anyone tell me how to INSERT mulitpul rows into a table at the same time?

I have a table with categories and sub categories, I would like for the user to be able to select ass many options as they want. So i have echoed out all of the cat and sub cat with checkbox next to them.
Please See
http://www.theeventorganiser.com/reg_more_cats.php

But i dont know how to set up the query so it will upload each cat and sub cat on a row of its own?
e.g
ROW 1
id=1
cat=Decor
sub= Inflatables

ROW 2
id=1
cat=DJs
sub= House
etc

Any help please, Just need an idea of how this coul be done thanks.

Link to comment
Share on other sites

So you have a table like this. I assume the id's are different despite your example?
[pre]
| id | cat    | subcat          |
|----|---------|-----------------|
| 1  | Decor  | Inflatables    |
| 2  | Decor  | Interior design |
| 3  | DJs    | Funky          |
| 4  | DJs    | House          |
| 5  | Laser  | Engineer        |
[/pre]

Name your checkboxes like this, giving each the id of the subcat as its value

[code]echo "<input type='checkbox' name='sub[]' value='$id'>";[/code]

As only check checkboxes are posted you can then save the users' requirements with

[code]<?php
foreach ($_POST['sub'] as $subcat) {

    mysql_query ("INSERT INTO mytablename (username, subcat)
                  VALUES ('$userid', '$subcat') ");
}
?>[/code]
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.