www.webdeveloper.com
Results 1 to 7 of 7

Thread: save data from multiple input form

  1. #1
    Join Date
    Jul 2012
    Posts
    5

    save data from multiple input form

    Hi, excuse me. Im new here, but i really need help. I can't find any idea to solve this.

    so,i want to save data that i input to the table.
    The table itself made from input form, consist row and columns as i order before.
    here is code for table input.php
    PHP Code:
    <form id="form1" name="form1" method="post" action="result.php">

    <
    tr>
    <
    td width="30%" align="left" valign="top">Input the number of columns     :<td height="37" align="left" valign="top"><input type="text" name="colums" value="" /></td>
    </
    tr>
    <
    tr>
    <
    td align="left" valign="top">Input the number of rows :</td>
    <
    td width="70%" align="left" valign="top"><input type="text" name="rows" value="" /></td>
    </
    tr>
    <
    tr>
    <
    td align="left" valign="top">&nbsp;</td>
    <
    td align="left" valign="top"><input type="submit" name="button" id="button" value="Submit" /></td>
    </
    tr>
    </
    table>
    </
    form
    and the result.php generate the table. each cell is input form.
    PHP Code:
    <?php
    $columns 
    $_POST['columns'];
    $rows $_POST['rows'];

    echo 
    "<form method='post' action='process.php'>";
    echo 
    "<table>";

    //made the columns
    for ($i0$i <=$baris-1$i++){

    //and the rows
    echo "<tr>";
    for (
    $j 0$j <= $kolom-1$j++) {

    //here is the input form, and each of data inputed here that i want to save it.
    $sum = array('[$i][$j]');
        echo 
    "<td> </td>
            <td><input size='5' type='text' name='data"
    .$sum."' /></td>
        "
    ;

    }
    }

    echo 
    "</tr>";
    echo 
    "<tr><td></td><td><input type='submit' name='submit' values='Submit' /></td></tr>";
    //im not sure here in value='$sum'
    echo "<tr><td></td><td><input type='hidden' name='banyak' value='$sum' /></td></tr>";
    echo 
    "</table>";
    echo 
    "</form>";

    // here,which one should i $_GET[''] ?

    ?>
    and, in process.php should show the average the all data, or any other math formula.
    i use the single input data in process.php,and its totally wrong :s


    ---------------------------
    sorry for my bad english..

  2. #2
    Join Date
    Apr 2010
    Posts
    227
    If you are new and in no great hurry then I recommend you ditch this code and learn instead to do it in ajax.

    So much nicer for the end user to use interactive websites that impliment ajax.

  3. #3
    Join Date
    Jul 2012
    Posts
    5
    actually, im in great hurry.
    the problem is, it wont save data input in form.
    even i made it as 2d array.

    could you give suggestion to ajax tutorial for my problem ?

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,145
    Not sure if this is your main problem, but you probably want the "row" loop to be the outer loop:
    PHP Code:
    $columns = (int) $_POST['columns'];
    $rows = (int) $_POST['rows']; 
    for(
    $row 0$row $rows$row++) {
      echo 
    "<tr>";
      for(
    $col 0$col $columns$col++) {
        echo 
    "<td>".($row $col)."</td>"
      
    }
      echo 
    "</tr>\n";

    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Jul 2012
    Posts
    5
    no,it's not.
    the rows and columns is okay. the problem is,how can i save the data that I input to the form inside the rows and columns,and i could use it later.

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,145
    sessions?
    database?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Jul 2012
    Posts
    5

    Resolved

    resolved. sorry, i made this so hardly to understand with foreign language in variable.

    so, for the input.php there's nothing to change.
    in result.php
    Code:
    $kolom is $columns
    $baris is $rows
    then, change this line
    PHP Code:
    //here is the input form, and each of data inputed here that i want to save it. 
    $sum = array('[$i][$j]'); 
        echo 
    "<td> </td> 
            <td><input size='5' type='text' name='data"
    .$sum."' /></td> 
        "

    and should be like this
    PHP Code:
    //here is the input form, and each of data inputed here that i want to save it. 
    $data = array("[$i][$j]");

        echo 
    "<td> </td>
            <td><input size='5' type='text' name='data[
    {$i}][{$j}]' value'foo'/> "; </td
    and doesn't need the hidden value as show in the line
    PHP Code:
    echo "<tr><td></td><td><input type='hidden' name='banyak' value='$sum' /></td></tr>"
    and to print data inside array, i use
    Code:
    $array = ($_POST['data'])
    which mean save 2d array to a new var, then could be use in future.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles