Author Topic: how i can get array value from txtbox inside while loop in php?  (Read 104 times)

israellaky

  • New Member
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
how i can get array value from txtbox inside while loop in php?
« on: February 03, 2012, 10:10:02 AM »
Hello everyone im creating a simple grading post.
My problem is how to get the array from multiple input type=text to update a tbl from mysql

here is my code:
PHP Code: [Select]
while($row=mysql_fetch_assoc($sql)){
$id=$row['id'];
$name=$row['studname'];
$cor=$row['course'];
$yl=$row['YearLevel'];

 
 
 
	
	

	
	
echo
"<tr bgcolor='#E6E6E6'>
	
	
<td align='left'><p align='left'>"
.$b.".".$name."</p><input type='text' name='cont[$a]' value=".$id."></td>
	
	
<td><p align='left'>"
.$cor."</p></td>
	
	

	
	
<td> <input type='text' name='pre[]' value=''style='width:40px;'></td>
	
	
<td> <input type='text' name='mid[]' value=''style='width:40px;' ></td>
	
	
<td> <input type='text' name='semi[]' value=''style='width:40px;' ></td>
	
	
<td> <input type='text' name='fin[]' value=''style='width:40px;' ></td>
	
	

	
	

	
	

	
	
</tr>"
;
	

	
	
$a++;
	
	
$b++;
	
	
$pre[]=$_POST['pre'];
	
	
	
}
	
	

	
	
  echo  
"
	
<tr> <td>
	
	
<input type='submit' name='update[$a]' value='Update'/>
	
 </td></tr>"
;


if user click the submit button   
 it well update the tble with same id

PHP Code: [Select]
if (isset($_POST['update'])){
	
	
	
 
	
	
 
	
	
	
	
  
	
	
	
	

	
	
	
	
foreach(
$_POST['pre'] as $key =>$val){
	
	
	
	
	
	

	
	
	
	
	
echo  
$val.'-'.$key.' <br/>';
	
	
	
	
	
 
	
	
	
	

	
	
	
	
}
	
	
 
	
	
	
	
 
	
	

	
	
 
	
	
	
	
 
	
	

	
	
	
	

	
	
 
	
	
	

	
	
}

How do I build a script and/or function that would get the value from input field in php?
sorry for my bad language im a beginner