Jump to content

Storing form data into array??


reyes99

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.