Solved

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

Posted on 2011-09-28
9
350 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
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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 109

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 109

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 109

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

832 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