Jump to content

how to access array from form on next page


gammaman

Recommended Posts

I know this may be partially a double post but I really need help.

If I have an array in a form like this

 

<input name = 'grd[]' size='5' type='text' />";

 

how do I access it on the next page.  I tried both ways and neither worked.

 

$var=$_POST['grd[]'];

$var=$_POST['grd'];

 

Just to let u know, $var=$_POST['grd']; will work, but u cant use echo in an array (as im guessing u did). U would need a for or foreach loop to display them.

 

<?php
$var = $_POST['grd'];
foreach($var as $val){
    echo $var;
}
?>

 

For your question. U need to insert those grades in one row, or multiples ones? Im guessing its the second option, so mainly the same code as above:

 

<?php
$var = $_POST['grd'];
foreach($var as $val){
    $resultsInsert = mysql_query("INSERT INTO grades (grade) VALUES ('$val')");
    echo 'Grade ' . $val . ' inserted correctly.<br />';
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.