I have two PHP files:
1) simplearraypost.php (containing the form)
2) echoarraypost.php (the validation of the form)
The form have 3 columns, which are
1) Row Number
2) Item Number
3) Description
Now, if posted, need validation per each cell of rows & columns!
Codes for both pasted here separately.
simplearraypost.php
<html>
<body>
<form name="insertitem" method="post" action="echoarraypost.php">
<table border="1">
<thead>
<tr>
<th>Row No.</th>
<th>Item</th>
<th>Description</th>
</tr>
</thead>
<?php
// Number of rows
$number = 10;
// Create rows
for ($i = 1; $i <= $number; $i++) {
echo ' <tr>' . "\n";
echo ' <td align="right">' . $i . '</td>' . "\n";
echo ' <td><input type="text" name="itemno[]" size="5"></td>' . "\n";
echo ' <td><input type="text" name="description[]" size="50"></td>' . "\n";
echo ' </tr>' . "\n";
}
?>
<tr>
<td colspan="4" align="right"><input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
</body>
</html>
echoarraypost.php
<?php
// store all posted item numbers and descriptions in local arrays
$itemnos = $_POST['itemno'];
$descriptions = $_POST['description'];
// loop through array
$number = count($itemnos);
for ($i = 0; $i < $number; $i++) {
// store a single item number and description in local variables
$itno = $itemnos[$i];
$desc = $descriptions[$i];
// this is where your insert should be (instead of the echo),
// insert the single values in $itnm and $desc
if ($itemnos[$i] <> "") {
echo "Item: " . $itno . " Description: " . $desc . "<p>";
}
else {
echo 'Error in row(s): ' . $i . ', <br>' . "\n"; // <-- How can I make this show the Row ID?
}
/* Un-Comment for checking posted info
// Check POST array
foreach ($_POST as $key => $value) {
echo '<p>'.$key.'</p>';
foreach($value as $k => $v) {
echo $k.'<br/>';
echo $v;
}
}
*/
}
?>
Your help is very much appreciated!
samimi_it
For anyone interested in the same issue,here is the final result I managed to come up with.
Comments and corrections are most welcome.