reyes99 Posted January 14, 2009 Share Posted January 14, 2009 Hi Everyone, I am having trouble figuring out how to store data from my form into an array and reading it. This is what I have so far. <?php echo "<form id='form1' name='form1' method='post' action=''><p> <label><input type='text' name='memberid[]' value='memberid' /></label></p><p> <label><input type='text' name='memberid[]' value='memberid' /></label></p><p> <label><input type='submit' name='submit' value='Submit' /></label></p> </form>"; $memberid = array("$memberid"); echo "output = " . print_r("$memberid"); ?> I get the following error: Notice: Undefined variable: memberid in C:\Program Files\EasyPHP 2.0b1\www\test.php on line 8 Arrayoutput = 1 Thanks Ralph Quote Link to comment Share on other sites More sharing options...
xtopolis Posted January 14, 2009 Share Posted January 14, 2009 That method is usually used for checkboxes <input type="checkbox" name="members[]" value="1" />Member 1 <input type="checkbox" name="members[]" value="2" />Member 2 Then AFTER YOU POST (submit the form) they are automatically in the $_POST['members'] array if any of them were checked, otherwise $_POST['members'] doesn't exist if none were checked. To accomplish what I think you want to do, perhaps looking at this threads will help: http://www.phpfreaks.com/forums/index.php/topic,223358.0.html Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted January 14, 2009 Share Posted January 14, 2009 Try to check this out: http://www.phpfreaks.com/tutorial/working-with-checkboxes-and-a-database Quote Link to comment Share on other sites More sharing options...
reyes99 Posted January 15, 2009 Author Share Posted January 15, 2009 That worked!! Thank you guys for your help. xtopolis here is what I did to fix it from your example, I have been tryting to get this to work for a week!! <?php echo "<form id='form1' name='form1' method='post' action=''><p> <label><input type='text' name='memberid[]' value='memberid' /></label></p><p> <label><input type='text' name='memberid[]' value='memberid' /></label></p><p> <label><input type='submit' name='submit' value='Submit' /></label></p> </form>"; foreach($_POST['memberid'] as $value){ echo "The value was $value<br />"; } ?> Thank you Daniel0 for the tutorial I will go through it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.