?
Solved

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

Posted on 2011-09-28
9
Medium Priority
?
378 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 

Author Comment

by:robdijo
ID: 36718622
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
ID: 36718646
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 1000 total points
ID: 36718647
$_POST is already an array. To "print" them use
print_r($_POST)

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 36718763
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
 
LVL 14

Expert Comment

by:Scott Madeira
ID: 36719531
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 111

Expert Comment

by:Ray Paseur
ID: 36719609
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 36720180
@smadeira,

You can't print an array

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

Expert Comment

by:Scott Madeira
ID: 36905474
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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 total points
ID: 36905680
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

764 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