Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question how to send form data to multiple database tables?

    hi, i am new to php and would appreciate any help i can get.

    i have a form with 3 fields and need the exact same data to be sent to multiple tables in the same database.

    Could anyone provide an example snippet of PHP code that would achieve this outcome.

    thanks so much

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    Yes its possible but why would you want that,

    sounds like a bad database design.
    PHP Code:
    $sql1 "INSERT INTO `database`.`table1` (`field1`, `field2`, `field3`) VALUES ('data1', 'data2', 'data3');";
    $sql2 "INSERT INTO `database`.`table2` (`field1`, `field2`, `field3`) VALUES ('data1', 'data2', 'data3');";
    $sql3 "INSERT INTO `database`.`table3` (`field1`, `field2`, `field3`) VALUES ('data1', 'data2', 'data3');"
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #3
    New to the CF scene
    Join Date
    May 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am using a joomla component called fabrik which connects to your database/ and/or database tables and displays the data in the front end of your site.

    You also create forms with fabrik which collects your data and sends it to a table that you specify. However Fabrik doesnt have a option to let you send data to multiple tables. BUT It does have a plugin field for the form that allows you to run php when the form is submitted, which would then allow you to send the form data to multiple tables. Problem is i don't know php very well!

    In the fabrik documentation they show some php that you can run to insert data into database: here is the link fabrikar.com/wiki/index.php/3.x_Common_PHP_tasks. Useing these methods what php code would i need to run to save my form data to multiple tables?

    Here is my original post in the fabrik forum asking how to do this: fabrikar.com/forums/index.php?threads/is-it-possible-to-send-data-from-1-fabrik-form-to-multiple-database-tables-not-lists.34099/unread

    To answer your question of why would i want the same data in multiple tables. Basically i have many users registered on my website. Each user needs to be able to access the same data which i plan to store in my "multiple tables" . Each table will represent a user i.e each user has their own table in the database.

    The reason for this is that the user needs to beable to delete records from the frontend ( something thant fabrik allows you to do), but the user needs to beable to delete records without effecting any other users account.

    So when new data is submitted via the form,i want it to go to all the tables i my database, and on the frontend my users are able to delete records in there own account (which will be displaying their table only). So each table will end up with different records stored on it as the user slowly deletes records over time.

    I hope this makes sense.

    thanks


  •  

    Posting Permissions

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