www.webdeveloper.com
Results 1 to 4 of 4

Thread: php form handler

  1. #1
    Join Date
    Oct 2004
    Posts
    9

    Post php form handler

    hey everyone i have a question about a form i have on my website.
    its handled by a simple INSERT INTO php script. the problem i have is that there is a "category" field on the form that has 4 options.
    the mysql database ive set up has 4 corresponding tables. can i use a set of conditionals to automatically send data to the correct table depending on what category they select?..or will i have to use a new form for each one?
    any feed back would be great.
    also, im new and id like to thank you guys in advance for any advice you have

  2. #2
    Join Date
    Oct 2004
    Posts
    9

    again

    i think i might have it. will this work?



    <form action="handle_form.php" method="post">
    <select multiple name="catgory[ ]">
    <option value=$_POST['"value"']>value</option>
    <option value=$_POST['"value"']>value</option>
    <option value=$_POST['"value"']>value</option>
    </select>
    </form>

    and then use:

    INSERT INTO "database" WHERE category =

    to determine what category is displayed?

  3. #3
    Join Date
    Sep 2004
    Location
    Boston, MA USA
    Posts
    94
    Just make the table definition in the SQL INSERT query a variable:

    Code:
    $selected_category=$_POST["category"];
    $query="insert into $selected_category (field, ..., field) values(value, ..., value);"
    Then execute $query using the appropriate PHP command for your database.

  4. #4
    Join Date
    Sep 2004
    Location
    Boston, MA USA
    Posts
    94
    As an aside, in the long run you might find it easier to consolidate all the tables into one, making "category" a field in the consolidated table.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles