Jump to content

Recommended Posts

hello
what i want to exactly is this:
in my code, i have used POST to get a variable to the next page. but the variable itself is also a variable.

for instance:

[code]<? $pagenumber= "2" ?>
<input name="page<?echo="$number"; ?>"[/code]

so my question is, how do i call on this variable in the next page?
these are the ones that i have tried yet.

[code] $pagenumber=$_POST['page' . '$number']
$pagenumber=$_POST['page$pagenumber'] [/code]

none of these work actually, and i even dont know wether its possible, but it would be unlogical if it weren't, wouldn't it.

If you have a way of making this work, via POST or other, let me know! the main idea is to get the value of a variable to the next page, and the value of this variable is" $variable" (yeah i know its darn confusing ;D)

thanks
OranniS
Link to comment
https://forums.phpfreaks.com/topic/21833-call-on-variable-variable-via-post/
Share on other sites

well what i want to do :
call on a variable wich was used in the previous page.I did this with POST.
so my ode would look like this:

<input name="awnser1">

-->then the code would be:

$awnser=$_POST['awnser1']

but the clue is that the thing i use POST on is also a variable:
so i get for instance:


<? $page_n=1; ?>
<input name="anwser<?echo"$page_n"?>">

so the server would compile the above as <input name="awnser1">
what i want to use in the next page now is the value "awnser$page_n", but i can't find a way to do this...
your $_POST is an array of all of the posted variables. the foreach loop does this:

for each array element in the $_POST array, assign the element name to $key and it's corresponding value to $value.  Then (for each one of these $key/$value pairs), make new variable that is named the same as the array element ($key).  so for example, let's say you have a posted variable called number1 that holds the value '1' so that code will in essence do this:

// $_POST['number1'] exists, cuz it was posted
foreach ($_POST as $key => $value) {
  $number1 = 1;
}

an alternative method is to use the [url=http://us2.php.net/extract]extract[/url] function:

extract ($_POST);

it pretty much does the same thing as the foreach loop, but there are extra arguments you can use, as far as overwriting pre-existing variable names, adding on prefixes, etc.. (refer to the linkie above)

yes, yes you can.  but, if  your script is generating variable names in your form, and then you are using the foreach or extract methods to change them from $_POST['blah'] to $blah.. i have to ask you why you wish to do this?  you don't know your variable names, so you won't be able to access them later.  The only reason why generating variable names is really useful is for keeping them in an array for easy looping in the first place.  In which case, there's really no point in doing this. 

well anyways, good lucks.
actually, that was the whole point, being able to acces them as they were afterwards...

anyway i got an error:

Warning: htmlspecialchars() expects parameter 1 to be string, array given in c:\phpdev\www\public\survey\vraag1.php on line 33

was i supposed to customize that piece of code?

edit:
aaah i get what you mean, the php script first generates the formname using the variable, then in the second page it generates a variable, using the formname that was compiled on the prevoious page,... well you'r right, thats not what i want, what i want is to have the complete syntax as it was before the compiling...
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.