Solved

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

Posted on 2011-09-28
9
359 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

820 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