Jump to content

[SOLVED] Just a quick question.


LiamProductions

Recommended Posts

Hey.

 

Is there a quicker of recieving all data for people with register globals off?

because if you have a big form with like 100 questions im sure people would'nt want to write 100 same lines of code to recieve each piece of data to the page then achually having to code the final result.

Is'nt there a quicker way with one line  or code or something to recieve all the data?

 

Link to comment
Share on other sites

if by "recieve [sic] the data" (i before except after which letter?) you mean localize the variables, extract() will do this for you.  alternatively, you can simply run a foreach() with dynamic variable generation:

 

foreach ($_POST AS $key => $val)
{
  $$key = $val;
}

 

i don't see the point in achually (i don't know what the 'h' is doing there, was 't' out for a pint?) localizing the variables, as this really doesn't save you too much time.  it also decreases your flexibility in dealing with multi-dimensional arrays and automating your query strings.

Link to comment
Share on other sites

.. no, extract() expects an array.  if you pass extract the $_POST array, it will pull all the $_POST variables into the local namespace using their keys as variable names.

 

perhaps i've misunderstood - what exactly are you asking?

Link to comment
Share on other sites

What i mean is if i post like 100 different data forms like a text field 100 different ones naming them like field name, address ect... i would have to write 100 different lines to get the data to the next page.

I want to know if theres a quicker way to recieve all the data on the page. A by pass through register globals or something.

Link to comment
Share on other sites

... i would have to write 100 different lines to get the data to the next page.

 

do you mean this sort of thing:

 

$fieldname1 = $_POST['fieldname1'];

 

if so, then use extract(), as i suggested.

 

Yes the code you just put is what i mean... but i want to know how to extract all the codes would it be something like

 

$alldata = extract($_POST['ALL_FIELDS'];

That code is probly wrong. but im hoping you can see what i want happening now,

Link to comment
Share on other sites

why not try things before asking if something will work?  your example clearly won't, but we're not here to spoon-feed you the answers - you can always give it a shot, see if it works, and if it doesn't, look around to figure out what's wrong rather than asking as a first resource.  a good programmer knows how to seek a simple answer to a simple question:

 

extract($_POST);

 

voila.

Link to comment
Share on other sites

@akitchin Sorry, but I'm going to try to simplify what you've been trying to explain. Correct me if I'm wrong.

 

@LiamProductions

Simply said, lets say you have two textfields, named "username" and "password"

 

Once submitted, they can be retrieved using:

 

  $_POST['username'] and/or $_POST['password']

 

Now, if you use extract like akitchin has demonstrated:

 

  extract($_POST);

 

after you run that line of code, username and password will become available using:

 

  $username and/or $password

 

And there you have it!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.