Registritation form for event

sbischoff 12 Nov, 2012
Hi there,

we have a big event next year, and I want to do the registration with help of chrono forms. There will be many groups, that will register for this event and one person will do the registration for each group.
Currently, my plan is a multipage form. The one guy gets to the first page and can fill out all the general information about the group. He also can choose, how much people he want to register and click "next". On page 2 are fields to put in firstname and lastname of each person in the same amount, the user specifies on first page.

For that I have a few questions:
[list]
  • How can I fill in that much fields on page two, which the user specifies on page one?

  • I need to save the information in a database and I need the information of the group (from page one) together with the specific user information in one db record.
  • [/list]

    Sorry for my bad english, because I'm not a native speaker.

    I hope someone can help me with this. I would be very glad.

    Thanks in advance and best regards
    Steffen
    sbischoff 13 Nov, 2012
    Come on. No one has an answer for me?
    GreyHead 13 Nov, 2012
    Hi sbischoff,

    I've just been away for ten days and am working through a long backlog of posts.

    I would use PHP in a Custom Element element on the second form to check how many members there are in the group and generate the required number of inputs.

    You can save all the data in the same database record either by saving it all after the second page or by saving after each page and passing the id of the new record to the second page in a hidden input so that record is updated.

    Bob
    sbischoff 13 Nov, 2012

    I've just been away for ten days and am working through a long backlog of posts.


    Hi Bob!
    Thank you for your answer and sorry for the impatience.

    I would use PHP in a Custom Element element on the second form to check how many members there are in the group and generate the required number of inputs.



    Can I do this with Chronoforms or would you suggest to genere the required number of inputs in php within the Custom Element?


    You can save all the data in the same database record either by saving it all after the second page or by saving after each page and passing the id of the new record to the second page in a hidden input so that record is updated.



    I think you misunderstood me. On first page, there are only the data for the group and on the second page are the informations of each group member.
    So let me give you an example:
    On the first page you can choose the group, maybe we call it "FC Barcelona". On the second page you have to specify the members of that group, like "Linoel Messi", "Cesc Fabregaz" and so on. I want to store the name AND the name of the group in two records. One DB-Record for Lionel and one for Cesc, every with the field "groupname" = "FC Barcelona".

    Do you understand what I mean and can you help me?

    Best Regards and thank you very much
    Steffen
    GreyHead 14 Nov, 2012
    Hi sbischoff,

    Can I do this with Chronoforms or would you suggest to genere the required number of inputs in php within the Custom Element?

    There is nothing built-in to ChronoForms to generate a variable number of elements but it is fairly simple to do using PHP in a Custom Element element.

    I think you misunderstood me. On first page, there are only the data for the group and on the second page are the informations of each group member.

    That is what I understood.

    You will need to think carefully how you save the data. You can do it all in one database table, or in two linked tables - one for the groups and the second for the members. Using two tables is a little more complicated to set up but much more flexible if you need to work with the tables later.

    Bob
    sbischoff 14 Nov, 2012

    Can I do this with Chronoforms or would you suggest to genere the required number of inputs in php within the Custom Element?

    There is nothing built-in to ChronoForms to generate a variable number of elements but it is fairly simple to do using PHP in a Custom Element element.



    Okay, but I'm not an expert in PHP. So can you give me a hint or a code snippet or something like that? I guess I need a for-loop, but what exactly do I have to do?

    I think you misunderstood me. On first page, there are only the data for the group and on the second page are the informations of each group member.

    That is what I understood.

    You will need to think carefully how you save the data. You can do it all in one database table, or in two linked tables - one for the groups and the second for the members. Using two tables is a little more complicated to set up but much more flexible if you need to work with the tables later.



    I want to use one database table and one row / entry for each user, but with alle the informations from both pages.

    Should I use a custom SQL command on the submit button to save the data in the database? Or can I find a solution for this with out of the box functionality of chrono forms?

    Best regards and again thank you very much
    Steffen
    GreyHead 15 Nov, 2012
    Hi Steffen,

    The PHP will be something like this:
    <div>
    <?php
    $count = $form->data['count'];
    for ( $i = 1; $i <= $count; $i++ ) {
      echo "<input type='text' name='first_name_{$i}' id='first_name_{$i}' value='' /> <input type='text' name='last_name_{$i}' id='last_name_{$i}' value='' /><br />"
    }
    ?>
    </div>


    For the Database save you may need to add code to handle the variable number of name inputs - but it depends on how you are structuring the table.
    Bob
    sbischoff 16 Nov, 2012

    For the Database save you may need to add code to handle the variable number of name inputs - but it depends on how you are structuring the table.



    Hi Bob,

    thank you for the php code, I tried and it worked very well, thank you!

    I think for the DB Save I will write php code to submit event, too. What do you think? I guess I can use the same "for" to do a SQL statement and update the SQL-DB?

    Regards
    Steffen
    GreyHead 17 Nov, 2012
    Hi Steffen,

    AS I said earlier it depends on how you want to save and work with the data. There are three ways I can think of off the top of my head.

    [list=a]
  • The messiest is to use a single table; guess the maximum number of group members (or to enforce one) and add a whole load of columns.

  • The simplest is to add one column for whole group and to encode all of the name data into a single string. PHP has two functions json_encode() or serialize() that will do this. I prefer json_encode() as it is more flexible.

  • The most useful is to use two tables. Add the data for the group to the first table and add the member detail to the second using a new record for each member and a group id to link them back to the group record.
  • [/list:o]

    Options b) and c) can both be set up with Custom code actions using a For loop to create the necessary value (for b) or MySQL query (for c).

    Bob
    sbischoff 17 Nov, 2012
    Hi Bob,

    thank you really very much for your help, the support here is really nice!

    I will take option b with the two tables to realise my stuff, thank you for the hint!

    But now there's another question and I hope you can help me with this again.

    On my second page, I have a submit button and I added a back button (by checking the checkbox within configuration of submit button) as well and it works well. I can put the information of the group, click "next page" and can go back to the first page. The informations of the group is filled in the form.
    Is there any chance, that the user will now choose another count of user fields, which will be generated by my custom element and the previosly data is shown again?

    So image that you write all group information and choose that you want to register 12 people. Now you go to "next page" and realise that there are 13 people to register, so you have to go back and choose "13" in the dropdown. Then you click "Next" and all data from before is not there anymore.

    I hope you can understand what's my problem!?

    Can you help me out of this?

    Regards and thanks in advance
    Steffen
    GreyHead 17 Nov, 2012
    Hi Steffen,

    You have two choices I think.

    One is to put a big notice on the first page saying: "Please check the number of members in your group carefully, if you need to change it you may have to re-enter the names".

    The second is to make the number variable and use JavaScript to show an 'Add One' button on the second page. There's an example in this thread.

    Bob
    sbischoff 17 Nov, 2012
    Sorry Bob,

    I have again a question and a problem.

    I don't get my data from first page to the last page, so I don't have all the informations to write to database.

    On first page I will in my group information. After clicking "next page" I can see all the informations in the debugger. So I fill out the userdata and on the confirmation page I only can see the user data, but not the group data.

    What am I doing wrong??

    Here are some screenshots, mabye you can figure out, what I am doing wrong?

    1st Page
    [attachment=3]1stPage.png[/attachment]

    2nd Page
    [attachment=2]2ndPage.png[/attachment]

    confirmation Page
    [attachment=1]confirmationPage.png[/attachment]

    Events
    [attachment=0]events_cr.png[/attachment]
    GreyHead 17 Nov, 2012
    Hi Steffen,

    I think that the multi-page action passes the data between pages but then the second page needs to pass it on again. To do this add hidden inputs on the second page with the same names then it should work OK.

    Alternatively save the data after the first page and pass on the record ID.

    Bob
    sbischoff 17 Nov, 2012
    Hey Bob!

    This works very good, thank you again very much.

    And now I have the next problem, sorry for that.

    Now I have all my data on the last page and want it to write it into the database.

    I have a custom code:
    <?php
    /* Datenbankserver - In der Regel die IP */
    $db_server = 'xxxx';
    /* Datenbankname */
    $db_name = 'xxxx';
    /* Datenbankuser */
    $db_user = 'xxxx';
    /* Datenbankpasswort */
    $db_passwort = 'xxxx';
    
    $db = @mysql_connect($db_server, $db_user, $db_passwort)
       or die ('Konnte keine Verbindung zur Datenbank herstellen');
    
    
    $Stamm = $form->data['Stamm'];
    $Ansprechpartner = $form->data['Ansprechpartner'];
    $Mail = $form->data['Mail'];
    $Telefon = $form->data['Telefon'];
    $Mobil = $form->data['Mobil'];
    $updatekey =  $form->data['updatekey'];
    
    $SQL_string = "INSERT INTO ZerzuraAnmeldungStamm
                   (Stamm, Ansprechpartner, Mail, Telefon, Mobil, updatekey)
                  VALUES
                   ('$Stamm', '$Ansprechpartner', '$Mail', '$Telefon', '$Mobil', '$updatekey')";
    
    mysql_db_query($db_name, $SQL_string, $db);
    
    $anzahl = $form->data['Anzahl'];
    
      for ( $i = 1; $i <= $anzahl; $i++ ) {
        $Vorname_{$i} =  $form->data['Vorname_{$i}'];
        $Name_{$i} = $form->data['Name_{$i}'];
        $Essen_{$i} = $form->data['Essen_{$i}'];
        $Kommentar_{$i} = $form->data['Kommentar_{$i}'];
    
        //if (($Vorname_{$i} != "") && ($Name_{$i} != "") && ($Name_{$i} != null)) {
            $SQL_string2 = "INSERT INTO ZerzuraAnmeldung
                       (Stamm, Vorname, Name, Essen, Kommentar)
                      VALUES
                       ('$Stamm_{$i}', '$Vorname_{$i}', '$Name_{$i}', '$Essen_{$i}', '$Kommentar_{$i}')";
            mysql_db_query($db_name, $SQL_string2, $db);
        //}
      }
    ?>


    But in my DB there is only one new record with "Array1" in every record.

    Can you help me?

    Best Regards and thank you!
    Steffen
    sbischoff 17 Nov, 2012
    Hi Bob!

    Sorry that I have to bother you again, but the "add row" button doesn't work.😟

    I've added this code to "Load JS" action on the "On Load" event:
    var m_count = 1;
    window.addEvent('domready', function() {
       $('add_row').addEvent('click', function(event) {
          form = event.target.getParent('form');
          addBlock(form);
       });
    });
    
    function addBlock(form) {
       var div, label, mat, men, ein, del, formCheck;
       // get the validation object
       formCheck = 'formCheck_' + form.get('name');
       formCheck = window[formCheck];
       // add the input elements
       div = new Element('div', {
          id: 'matdiv' + m_count
       });
       label = new Element('label', {
          For: 'material' + m_count,
          text: 'Material ' + m_count
       });
       label.inject(div);
       mat = new Element('input', {
          type: 'text',
          name: 'material' + m_count,
          id: 'material' + m_count,
          Class: "validate['required']"
       });
       formCheck.register(mat);
       mat.inject(div);
       men = new Element('input', {
          type: 'text',
          name: 'menge' + m_count,
          id: 'menge' + m_count,
          Class: "validate['required']"
       });
       formCheck.register(men);
       men.inject(div);
       ein = new Element('input', {
          type: 'text',
          name: 'einheit' + m_count,
          id: 'einheit' + m_count
       });
       ein.inject(div);
       // add a new delete button
       del = new Element('input', {
          type: 'button',
          name: 'del' + m_count,
          id: 'del' + m_count,
          value: 'Delete',
          styles: {
             width: '100px'
          }
       });
       // add a click event to the new delete button
       del.addEvent('click', function(event) {
          delRow(event.target.id, event.target.value);
       });
       del.inject(div);
       div.inject($('add_here'));
       // increment counter
       m_count += 1;
       div.inject($('add_here'));
       // add event to del
    }
    
    function delRow(row, value) {
       // get the row number from the button id
       row = row.replace('del', '');
       if(value == 'Delete') {
          // if 'delete' disable all the inputs
          $('material' + row).disabled = true;
          $('menge' + row).disabled = true;
          $('einheit' + row).disabled = true;
          // set the button to 'Undelete'
          $('del' + row).value = 'Undelete';
       } else {
          // enable all the inputs
          $('material' + row).disabled = false;
          $('menge' + row).disabled = false;
          $('einheit' + row).disabled = false;
          // set the button to 'Delete'
          $('del' + row).value = 'Delete';
       }
    }


    And then I add a button with id "add_row" but nothing happened, when I push the button in the form!? Can you help me again please?
    GreyHead 18 Nov, 2012
    Hi Steffen,

    Please post your images here using the Upload Attachment link under the message editor. I've had enough trying to get past the **** popups.

    The add row button looks OK; the problem is more likely to be with the JavaScript. Do you see any error messages in the Console?

    Bob
    sbischoff 22 Nov, 2012
    Hi Bob,

    sorry, but I didn't know, that Imagebanana produce popups. From now I will upload my images at the forum.

    Today I had time to continue work with the form, but it didn't work...😟

    This is my JS-Code:
    var m_count = 1;
    window.addEvent('domready', function() {
       $('add_row').addEvent('click', function(event) {
          form = event.target.getParent('form');
          addBlock(form);
       });
    });
    
    function addBlock(form) {
       var div, label, mat, men, ein, del, formCheck;
       // get the validation object
       formCheck = 'formCheck_' + form.get('name');
       formCheck = window[formCheck];
       // add the input elements
       div = new Element('div', {
          id: 'matdiv' + m_count
       });
       label = new Element('label', {
          For: 'material' + m_count,
          text: 'Material ' + m_count
       });
       label.inject(div);
       mat = new Element('input', {
          type: 'text',
          name: 'material' + m_count,
          id: 'material' + m_count,
          Class: "validate['required']"
       });
       formCheck.register(mat);
       mat.inject(div);
       men = new Element('input', {
          type: 'text',
          name: 'menge' + m_count,
          id: 'menge' + m_count,
          Class: "validate['required']"
       });
       formCheck.register(men);
       men.inject(div);
       ein = new Element('input', {
          type: 'text',
          name: 'einheit' + m_count,
          id: 'einheit' + m_count
       });
       ein.inject(div);
       // add a new delete button
       del = new Element('input', {
          type: 'button',
          name: 'del' + m_count,
          id: 'del' + m_count,
          value: 'Delete',
          styles: {
             width: '100px'
          }
       });
       // add a click event to the new delete button
       del.addEvent('click', function(event) {
          delRow(event.target.id, event.target.value);
       });
       del.inject(div);
       div.inject($('add_here'));
       // increment counter
       m_count += 1;
       div.inject($('add_here'));
       // add event to del
    }
    
    function delRow(row, value) {
       // get the row number from the button id
       row = row.replace('del', '');
       if(value == 'Delete') {
          // if 'delete' disable all the inputs
          $('material' + row).disabled = true;
          $('menge' + row).disabled = true;
          $('einheit' + row).disabled = true;
          // set the button to 'Undelete'
          $('del' + row).value = 'Undelete';
       } else {
          // enable all the inputs
          $('material' + row).disabled = false;
          $('menge' + row).disabled = false;
          $('einheit' + row).disabled = false;
          // set the button to 'Delete'
          $('del' + row).value = 'Delete';
       }
    }


    And the second problem is, that the SQL-Statement also doesn't work. It only writes "Array" into the database, like I wrote a couple of days ago.

    Can you please help me again??

    Thank you
    Steffen
    GreyHead 23 Nov, 2012
    Hi Steffen,

    For the JavaScript I have the same question - do you see any errors in the JavaScript Console using your web browser develop tools?

    For the MySQL I suspect that the problem is the lines like this
    $Vorname_{$i} =  $form->data['Vorname_{$i}'];

    as the PHP {$i} syntax only works inside double quotes ""

    Personally, I'd probably redesign the input naming to use array names and make this stage simpler.

    Bob
    sbischoff 23 Nov, 2012
    Hi Bob,

    For the JavaScript I have the same question - do you see any errors in the JavaScript Console using your web browser develop tools?



    there is no output from console within google chrome, if I click the button "Add Row".
    [attachment=1]Clipboard_2012-11-24_00-50-30.png[/attachment]
    And the same problem with Firefox.
    [attachment=0]Firefox.png[/attachment]

    For the MySQL I suspect that the problem is the lines like this

    $Vorname_{$i} =  $form->data['Vorname_{$i}'];

    as the PHP {$i} syntax only works inside double quotes ""



    I've tried, but I don't know, if I'm doing right...

    Here is my code to generate the fields for the participants
    <div>
    <table>
      <thead>
        <td><strong>Vorname</strong></td>
        <td><strong>Name</strong></td>
        <td><strong>Anreise mit dem Zug</strong></td>
        <td><strong>Kommentar</strong></td>
        </thead>
      <?php
        for ( $i=0; $i < 20; $i++ ) {
            echo "<tr>";
            echo "<td><input type='text' maxlength='150' size='30' name='Vorname_$i' id='Vorname_$i' value='' class=' validate['required']'/> </td>";
            echo "<td><input type='text' maxlength='150' size='30' name='Name_$i' id='Name_$i' value='' class=' validate['required']'/></td>";
            echo "<td><select name='Zug_$i' size='1' id='Zug_$i' class=' validate['required']'>";
    	    echo "<option value='1' selected>Ja</option>";
    	    echo "<option value='0'>Nein</option></select></td>";
    	    echo "<td><input type='text' maxlength='150' size='30' name='KommentarTN_$i' id='KommentarTN_$i' value='' class=' validate['required']'/> </td>";
    	    echo "</tr>";
        }
      ?>
    </table>
    </div>


    And this Code I use now for MySQL command:
    for ( $i = 0; $i < 20; $i++ ) {
        $Vorname_$i =  $form->data['Vorname_"{$i}"'];
        $Name_$i = $form->data['Name_"{$i}"'];
        $Zug_$i = $form->data['Zug_"{$i}"'];
        $KommentarTN_$i = $form->data['KommentarTN_"{$i}"'];
    
        //if (($Vorname_{$i} != "") && ($Name_{$i} != "") && ($Name_{$i} != null)) {
            $SQL_string2 = "INSERT INTO ZerzuraAnmeldung
                       (Stamm, Name, Vorname, Zug, Kommentar)
                      VALUES
                       ('$Stamm_"{$i}"', '$Name_"{$i}"', '$Vorname_"{$i}"', '$Zug_"{$i}"', '$KommentarTN_"{$i}"')";
            mysql_db_query($db_name, $SQL_string2, $db);
        //}
      }


    Thank you for your support!

    Regards
    Steffen
    GreyHead 24 Nov, 2012
    Hi Steffen,

    This is definitely wrong:
    VALUES
                       ('$Stamm_"{$i}"', '$Name_"{$i}"', '$Vorname_"{$i}"', '$Zug_"{$i}"', '$KommentarTN_"{$i}"')";

    and this is probably wrong:
    $Vorname_$i =  $form->data['Vorname_"{$i}"'];


    Please add debugging code to see exactly what values you are creating and check the PHP manual to see what the correct syntax is.

    As I said earlier I'd use array names to make all this simpler.

    Bob
    sbischoff 02 Dec, 2012
    Hi Bob,

    I need again your help please, because my SQL-Update still doesn't work.😟

    Here is my PHP-Code:
    for ( $i = 0; $i < 20; $i++ ) {
        $Vorname =  $form->data['Vorname_'][$i];
        $Name = $form->data['Name_'][$i];
        $Zug = $form->data['Zug_'][$i];
        $KommentarTN = $form->data['KommentarTN_'][$i];
    
             $SQL_string2 = "INSERT INTO ZerzuraAnmeldung
                       (Stamm, Name, Vorname, Zug, Kommentar)
                      VALUES
                       ('$Stamm', '$Name', '$Vorname', '$Zug', '$KommentarTN')";
            mysql_db_query($db_name, $SQL_string2, $db);
         echo $SQL_string2;
        //}
      }


    and this is the SQL-Statement that the code generates:
    INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', 'asdf', 'adsfadsf', '1', 'a')INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', 'adsfasdf', 'asdfagasdf', '1', 'd')INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '')INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '')INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '')INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '')INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '')INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '')INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '')INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '')INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '')INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '')INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '')INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '')INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '')INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '')INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '')INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '')INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '')INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '')


    At the moment only the first entry is insert into the database, all other entries get lost.

    Can you please give me a hint, what I have to do?

    Thank you very much in advance!

    Regards
    Steffen
    GreyHead 02 Dec, 2012
    Hi Steffen,

    It looks as though you are missing the semi-colon ; at the end of the query.

    Bob

    PS I'm would set it up as a single query with multiple value sets rather than multiple queries
    INSERT INTO `ZerzuraAnmeldung`
    (Stamm, Name, Vorname, Zug, Kommentar) 
    VALUES ('20/02/07', 'asdf', 'adsfadsf', '1', 'a'), 
      ('20/02/07', 'adsfasdf', 'asdfagasdf', '1', 'd'),
      ('20/02/07', '', '', '1', '',
      ('20/02/07', '', '', '1', ''),
      ('20/02/07', '', '', '1', ''),
      . . .
      ('20/02/07', '', '', '1', '') ;

    Bob
    sbischoff 02 Dec, 2012

    It looks as though you are missing the semi-colon ; at the end of the query.



    Also with the semi-colon the query doesn't work...😟

    for ( $i = 0; $i < 20; $i++ ) {
        $Vorname =  $form->data['Vorname_'][$i];
        $Name = $form->data['Name_'][$i];
        $Zug = $form->data['Zug_'][$i];
        $KommentarTN = $form->data['KommentarTN_'][$i];
    
        //if (($Vorname_{$i} != "") && ($Name_{$i} != "") && ($Name_{$i} != null)) {
            $SQL_string2 = "INSERT INTO ZerzuraAnmeldung
                       (Stamm, Name, Vorname, Zug, Kommentar)
                      VALUES
                       ('$Stamm', '$Name', '$Vorname', '$Zug', '$KommentarTN');";
            mysql_db_query($db_name, $SQL_string2, $db);
         echo $SQL_string2;
        //}
      }


    INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', 'asdf', 'adsfadsf', '1', 'a');INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', 'adsfasdf', 'asdfagasdf', '1', 'd');INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '');INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '');INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '');INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '');INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '');INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '');INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '');INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '');INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '');INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '');INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '');INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '');INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '');INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '');INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '');INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '');INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '');INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/02/07', '', '', '1', '');


    PS I'm would set it up as a single query with multiple value sets rather than multiple queries

    INSERT INTO `ZerzuraAnmeldung`
    (Stamm, Name, Vorname, Zug, Kommentar) 
    VALUES ('20/02/07', 'asdf', 'adsfadsf', '1', 'a'), 
      ('20/02/07', 'adsfasdf', 'asdfagasdf', '1', 'd'),
      ('20/02/07', '', '', '1', '',
      ('20/02/07', '', '', '1', ''),
      ('20/02/07', '', '', '1', ''),
      . . .
      ('20/02/07', '', '', '1', '') ;



    Can you show me, how my php code should looks, if you want to use a single query?

    Thank you very much!
    Steffen
    GreyHead 02 Dec, 2012
    Hi Dteffen,

    Then please paste the query into PHPMyAdmin and see what error message you get.

    Bob
    sbischoff 02 Dec, 2012

    Then please paste the query into PHPMyAdmin and see what error message you get.



    Hey Bob,

    this is the error message from my PHPMyAdmin:

    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO ZerzuraAnmeldung (Stamm, Name, Vorname, Zug, Kommentar) VALUES ('20/' at line 2
    sbischoff 02 Dec, 2012
    Hi Bob,

    I guess I got it...finally

    $SQL_string2 = "INSERT INTO ZerzuraAnmeldung(Stamm, Name, Vorname, Zug, Kommentar) VALUES ";
    
      for ( $i = 0; $i < 20; $i++ ) {
        $Name = $form->data['Name_'][$i];
        $Vorname =  $form->data['Vorname_'][$i];
        $Zug = $form->data['Zug_'][$i];
        $KommentarTN = $form->data['KommentarTN_'][$i];
    
        $NameTMP = trim($Name);
        $VornameTMP = trim($Vorname);
    
        if ((!empty($NameTMP)) && (!empty($VornameTMP))) {
            $SQL_string3 = $SQL_string3 . "('$Stamm', '$Name', '$Vorname', '$Zug', '$KommentarTN'),";
        }
      }
    
      $SQL_string4 = $SQL_string2 . $SQL_string3;
      $SQL_string5 = substr($SQL_string4, 0, -1);
      mysql_db_query($db_name, $SQL_string5, $db);
    ?>


    This works for me now. Thank you again very much for your help!

    Thanks
    Steffen
    GreyHead 03 Dec, 2012
    Hi Steffen,

    Well done :-)

    Bob
    This topic is locked and no more replies can be posted.