0

So I have a PHP page (labeled page_2) that is being passed data from a POST request from a form from another page (page_1) (let's label them form_1 and form_2. Let's say form_1 hold the data data_1 and form_2 holding data_2.

As for the script, I'm attempting to insert the data from both form_1 and form_2 into a variable defined via page_2.

So far I have the following:

<?php
$var = "alpha=$_POST['form_2']&beta=$_POST['form_2']"
echo $var
?>

The expected output is:

alpha=data_1&beta=data_2

However, I get no output. Any ideas?

ivaigult
  • 6,198
  • 5
  • 38
  • 66
  • Show us your form code... – Amanjot Kaur Jan 22 '20 at 18:22
  • 1
    Array keys inside of a double-quoted string should not have single quotes. Try `$_POST[form_2]`, or surrounded the variable with curly brackets `{$_POST['form_2']}` – aynber Jan 22 '20 at 18:23
  • 1
    You've got syntax errors in your code. You can run `php -l ` from the command line to perform a syntax check, or enable error reporting so that you get runtime errors. – Alex Howansky Jan 22 '20 at 18:24
  • https://stackoverflow.com/questions/871858/php-pass-variable-to-next-page – Amanjot Kaur Jan 22 '20 at 18:25
  • This also might be helpful - on multi-paged forms: https://www.hashbangcode.com/article/multi-page-forms-php – Hektor Jan 22 '20 at 19:23
  • "[Q]uoted keys only work using the curly brace syntax" -[Complex (curly) syntax](https://www.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex) – showdev Jan 22 '20 at 19:37
  • Minor formatting improvements – ivaigult Jan 23 '20 at 11:23

0 Answers0