Hello,

I would like to know how can I insert into multiple mysql databases using one php form.

I want different data to go into each tables. For example, I have three tables, fruits vegetables dairy, and I would like respective things to go into each table.

    There's no magic involved, just POST the form and insert into each table the same as if you were only inserting into one table (but with three separate INSERT statements).

      The code I'm using is

      $sql= "INSERT INTO `Table 1` (Column 1, Column 2) VALUES (Value 1, Value 2)"';
      $sql= "INSERT INTO `Table 2` (Column 1, Column 2) VALUES (Values 1, Values 2)";

      But nothing appears in the mysql table, although the echo does show up as "successful"

      Is there a reason why the information is not making it into the mysql database?

        Notice how the syntax highlighting shows a problem? You have an extraneous single quote after the string closing double quote on the end of the line for $sql. Also you are assigning the same variable twice so only the last assignment will work at best (none will until you fix the syntax error)

          Derokorian;10983857 wrote:

          Notice how the syntax highlighting shows a problem? You have an extraneous single quote after the string closing double quote on the end of the line for $sql. Also you are assigning the same variable twice so only the last assignment will work at best (none will until you fix the syntax error)

          Oh thank you, I have removed the extra quote.

          How do I assign different variables to the assignments? Can you give me an example?

            I think you should have one table for "things" and add a column for "thing type" eg fruit/veg /dairy
            It would make adding a new category much easier and allow the code to be less tied in to your item structure

              cretaceous;10983881 wrote:

              I think you should have one table for "things" and add a column for "thing type" eg fruit/veg /dairy
              It would make adding a new category much easier and allow the code to be less tied in to your item structure

              The above code is only an example. I have an html for with a diverse ordering of questions, and each of the questions are going to a different mysql table.

                Write a Reply...