/    Sign up×
Community /Pin to ProfileBookmark

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

[code=php]
<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>[/code]

and the result.php generate the table. each cell is input form.

[code=php]<?php
$columns = $_POST[‘columns’];
$rows = $_POST[‘rows’];

echo “<form method=’post’ action=’process.php’>”;
echo “<table>”;

//made the columns
for ($i= 0; $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[”] ?

?>[/code]

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..

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@BelrickJul 05.2012 — 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.
Copy linkTweet thisAlerts:
@snipe42authorJul 06.2012 — 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 ?
Copy linkTweet thisAlerts:
@NogDogJul 06.2012 — Not sure if this is your main problem, but you probably want the "row" loop to be the outer loop:
[code=php]
$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";
}
[/code]
Copy linkTweet thisAlerts:
@snipe42authorJul 08.2012 — 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. ?
Copy linkTweet thisAlerts:
@NogDogJul 08.2012 — sessions?

database?
Copy linkTweet thisAlerts:
@snipe42authorJul 12.2012 — 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[/CODE]


then, change this line[code=php]//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>
"; [/code]


and should be like this[code=php]//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>[/code]


and doesn't need the hidden value as show in the line
[code=php]echo "<tr><td></td><td><input type='hidden' name='banyak' value='$sum' /></td></tr>";
[/code]


and to print data inside array, i use [CODE]$array = ($_POST['data'])[/CODE]
which mean save 2d array to a new var, then could be use in future.
×

Success!

Help @snipe42 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.22,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...