getting data from multiple forms

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • goresus
    New Member
    • Nov 2006
    • 10

    getting data from multiple forms

    Hello,

    I have prepared a form and it is in its final stage. One thing that remains is the following: when I click a submit button in the page, all the information in the page, from different forms, needs to be collected and entered into a table.

    I have created a new form with a button and once I click that button, it calls a new php (closeBill.php) file. I had planned that in this php file I would collect data from the page and just update the required table. But I am faced with the problem of not being able to access the values in the fields in the first file. If my explanation does not make sense please look at the following codes that I have included, may be it will make my problem apparent.

    This is a part of the code from the page that contains the data:
    [php]
    .
    .
    .

    <FORM NAME='topButton 3' METHOD='post' ACTION='closeBi ll.php'>
    // this is the submit button in question
    <td width="25%"><in put type="submit" value="Close Bill" name="clob">
    </td>
    </FORM>
    </tr>
    </table>
    <!--nested table 2-->
    <table border="1" bordercolor="" width="100%" bgcolor="">

    <FORM NAME='waiterLog ' id = 'waiterLog' METHOD='POST' ACTION='waiterL og.php'>
    <!--row 2-->
    <tr>
    <td width = "80" align = "right" >Waiter</td>
    <td width = "10"></td>
    <td width = "50">

    //i amtrying to get this value into a variable after submitting the form
    <select id = "loggedWait ers" name="loggedWai ters">
    <option value='0'>logge d waiters</option>
    <?php
    $loggedWaiterTa ble_sql = "SELECT * FROM LoggedWaiterNam e";
    $loggedWaiterTa ble_result = mysql_query($lo ggedWaiterTable _sql, $db);

    $counter = 1;
    while ($row = mysql_fetch_ass oc($loggedWaite rTable_result)) {
    $waiterID = $row['waiterID'];
    echo "<option value='$waiterI D'>" . $waiterID . "</option>\n\t";
    $counter++;
    }
    ?>

    </select></td>
    </td>
    </FORM>[/php]


    Once the closeBill button is clicked, it goes to this field:

    [php]<?php


    include("db_con nect.php");

    //this is the part that does not work
    $waiter_Email = $_POST['waiterLog.logg edWaiters'];
    if($waiter_Emai l != NULL)
    echo $waiter_Email;
    else echo "no data"; //this is what prints out

    //this part works fine
    $closeBill2_sql = "TRUNCATE TABLE BillSpreadsheet ";
    mysql_query($cl oseBill2_sql, $db);
    include("ssa.ph p");
    ?>
    [/php]
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Without looking too deep, the following springs up
    [php]$waiter_Email = $_POST['waiterLog.logg edWaiters'];[/php]
    The fields are posted by name, so this statement should be:
    [php]$waiter_Email = $_POST['loggedWaiters'];
    [/php]

    Ronald :cool:

    Comment

    • seangates
      New Member
      • Dec 2006
      • 19

      #3
      goresus,

      You have to put the forms together. Whatever form you submit gets submitted. So, when you click the submit button for the first form (topButton3), you don't get anything because there are no other fields besides the button itself.

      So, you need to combine them, kinda like this:
      [php]
      <FORM NAME='topButton 3' METHOD='post' ACTION='closeBi ll.php'>
      <td width="25%"><in put type="submit" value="Close Bill" name="clob">
      </td>
      </tr>
      </table>
      <!--nested table 2-->
      <table border="1" bordercolor="" width="100%" bgcolor="">
      <!--row 2-->
      <tr>
      <td width = "80" align = "right" >Waiter</td>
      <td width = "10"></td>
      <td width = "50">

      //i amtrying to get this value into a variable after submitting the form
      <select id = "loggedWait ers" name="loggedWai ters">
      <option value='0'>logge d waiters</option>
      <?php
      $loggedWaiterTa ble_sql = "SELECT * FROM LoggedWaiterNam e";
      $loggedWaiterTa ble_result = mysql_query($lo ggedWaiterTable _sql, $db);

      $counter = 1;
      while ($row = mysql_fetch_ass oc($loggedWaite rTable_result)) {
      $waiterID = $row['waiterID'];
      echo "<option value='$waiterI D'>" . $waiterID . "</option>\n\t";
      $counter++;
      }
      ?>

      </select></td>
      </td>
      </FORM>[/php]
      Now, that convention is not valid HTML because the <form> tags should really wrap around the <table> tags, and not inside them anywhere.

      Hope this helps.
      Sean
      Last edited by seangates; Dec 4 '06, 08:10 PM. Reason: fixed html tags in post

      Comment

      Working...