Announcement

Collapse
No announcement yet.

Insert on multiple tables?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Insert on multiple tables?

    Hello,

    I have an aplication about register projects and validation by the bosses. First i have a form to document the project, and i have two tables, one "documentation" is the one where all the project data is saved and the second one validation, is where the name of the person who validate, date and area to aply is save.

    Both has a field call id_project that is a consecutive that increase automatically.

    When i save the form documentation the data is save in the first table but i also want the id_project could be insert in the second one.

    You have an idea of how can i do this??

  • #2
    Yes, you can add custom code in the onbeforeinsert or onafterinsert event. Just create the event and in the editor you have on the right side a few snippets you can choose from. One is for insert data into another table.
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development
    www.scriptcase.eu / www.scriptcase.nl

    Comment


    • #3
      thank you! i create an event onafterinsert with the next code, the aplication dont send any errors, but insert a zero and not the right value

      /**
      * Insert a record on another table
      */

      // SQL statement parameters
      $insert_table = 'validation'; // Table name
      $insert_fields = array( // Field list, add as many as needed
      'id_proyecto' => "'id_proyecto'",
      );

      // Insert record
      $insert_sql = 'INSERT INTO ' . $insert_table
      . ' (' . implode(', ', array_keys($insert_fields)) . ')'
      . ' VALUES (' . implode(', ', array_values($insert_fields)) . ')';

      sc_exec_sql($insert_sql);


      the problem could be that the field is a consecutive that increase automatically??

      Comment


      • #4
        If you have declared an autoincement field than you have to retrieve this value and use it in your insert. In Mysql you can use last insert value. To access the fields from your screen you need to put them between {}
        So I would expect a statement like array('myfield'=>{myfieldfromscreen}, etc.
        Albert Drent
        aducom software netherlands
        scriptcase partner, reseller, support and (turn-key) development
        www.scriptcase.eu / www.scriptcase.nl

        Comment


        • #5
          Thank you! it works!

          Comment

          Working...
          X