Support Forums

Full Version: plz help me with multiple textboxes in php
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i m new to php , i want to know how get data from multiple textboxes
can i name text boxes as like a arry, is it correct ,and how to display them
i return them like this echo $_POST[txtName[0]]
but it is not working , plz help me

this is the code

<html>
<head><title>Student Marks Calculator </title></head>
<body>
<form name ="My Data" method ="POST">
<table>
<tr>
<td>Name</td><td>Maths</td><td>Science</td><td>English</td>
</tr>
<tr
<td><input type="text" name=txtName[0]/></td>
<td><input type="text" name=txtMaths[0] /></td>
<td><input type="text" name=txtScience[0] /></td>
<td><input type="text" name=txtEnglish[0] /></td>
</tr>
<tr>
<td><input type="text" name=txtName[1]" /></td>
<td><input type="text" name=txtMaths[1]" /></td>
<td><input type="text" name=txtScience[1]" /></td>
<td><input type="text" name=txtEnglish[1]" /></td>
</tr>
<tr>
<td><input type="text" name=txtName[2] /></td>
<td><input type="text" name=txtMaths[2] /></td>
<td><input type="text" name=txtScience[2] /></td>
<td><input type="text" name=txtEnglish[2] /></td>
</tr>
<tr>
<td><input type="text" name=txtName[3] /></td>
<td><input type="text" name=txtMaths[3] /></td>
<td><input type="text" name=txtScience[3] /></td>
<td><input type="text" name=txtEnglish[3] /></td>
</tr>
<tr>
<td><input type="Submit" name="Report" value="Gen Report" /></td>
<td><input type="Submit" name="Reset" value="Reset" /></td>
</tr>

<?php



?>

</body>
</html>
Remove the numbers from the arrays (I don't know if that would stop it working but I personally don't put it in. Then you'd do this:

PHP Code:
foreach($_POST['txtName'] as $key => $val)
{
    
//each iteration of the loop would deal with each 'txtName' field


See how that works.
thanks MattR ,