Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
plz help me with multiple textboxes in php
#1
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>
Reply
#2
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.
MyBB Support Team Lead
Reply
#3
thanks MattR ,
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PHP Framework List: An Ultimate Guide to 102 PHP Frameworks for Web Developers tk-hassan 0 941 07-27-2020, 11:26 PM
Last Post: tk-hassan
  PHP Video Tutorials (PHP For Beginners) Eleqtriq 4 3,666 10-10-2011, 01:00 PM
Last Post: Greyersting

Forum Jump:


Users browsing this thread: 1 Guest(s)