gammaman Posted April 26, 2008 Share Posted April 26, 2008 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']; Link to comment https://forums.phpfreaks.com/topic/103079-how-to-access-array-from-form-on-next-page/ Share on other sites More sharing options...
BlueSkyIS Posted April 26, 2008 Share Posted April 26, 2008 print_r($_POST['grd[]']); both ways and see what you get? Link to comment https://forums.phpfreaks.com/topic/103079-how-to-access-array-from-form-on-next-page/#findComment-527974 Share on other sites More sharing options...
gammaman Posted April 26, 2008 Author Share Posted April 26, 2008 This is the one that is working. print_r($_POST['grd']); Now a tough question for an expert like you. How would I store that in a variable so that I could do a query and insert each grade into its proper row. Link to comment https://forums.phpfreaks.com/topic/103079-how-to-access-array-from-form-on-next-page/#findComment-527979 Share on other sites More sharing options...
Fadion Posted April 27, 2008 Share Posted April 27, 2008 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 />'; } ?> Link to comment https://forums.phpfreaks.com/topic/103079-how-to-access-array-from-form-on-next-page/#findComment-528055 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.