Solved

How do I store variables from a _POST to an array in PHP

Posted on 2011-09-28
9
322 Views
Last Modified: 2012-05-12
I have a bunch of variables that are defined from a _POST from an incoming form.  I need to put all the variables that are defined into an array.

I tried -->

$myArray=array($field1, $field2, $field3);
print $myArray;

This is only outputting Array on my web browser.  I am new to PHP so this is probably something easy to fix I am missing.  When I Google the term variables in php array I really don't see any examples that help.
0
Comment
Question by:robdijo
  • 3
  • 2
  • 2
  • +2
9 Comments
 

Author Comment

by:robdijo
Comment Utility
Actually - here is my new ARRAY script via some research but still no luck:

$myArray = array(

"website" => $website, "check' => $check, "points" => $points
);

print $myArray;
0
 
LVL 8

Expert Comment

by:Rik-Legger
Comment Utility
I'm not sure how you defined your _POST variables like your saying in your fist post,
but perhaps you need to do it like this:

$myArray = array(

"website" => $_POST['website'], "check' => $_POST['check'], "points" => $_POST['points']
);

print $myArray;

Open in new window

0
 
LVL 26

Accepted Solution

by:
EddieShipman earned 250 total points
Comment Utility
$_POST is already an array. To "print" them use
print_r($_POST)

Open in new window

0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
This function is your friend when you are not sure what the data looks like...
http://php.net/manual/en/function.var-dump.php
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 14

Expert Comment

by:Scott Madeira
Comment Utility
You can't print an array.  You can print things that are in the array.  

echo $array['fieldname'];


As Ray stated, if you want to see what is in your array then use var_dump($array);
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
0
 
LVL 26

Expert Comment

by:EddieShipman
Comment Utility
@smadeira,

You can't print an array

That is what print_r() is for, DUH!
0
 
LVL 14

Expert Comment

by:Scott Madeira
Comment Utility
Eddie,

You can't:

print $array;   // which is what he was trying to do in the original post.

double DUH!!!!


Read my whole post....  as I said, if you want to see the contents of the array (which will print them on the screen) you need to use var_dump or print_r.
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
Comment Utility
When I Google the term variables in php array I really don't see any examples that help.

Don' t bother with Google.  Just use the PHP.net web site.  Start your learning adventure here:
http://php.net/tut.php
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now