Solved

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

Posted on 2011-09-28
9
377 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 250 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 110

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 110

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 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 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

Technology Partners: 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!

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

691 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