[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

A very basic form and php question.

I am asking this question with blushing face; it is really basic, but I don't get this right. Pleas help me!

Processing the attached piece of code, I had expected to get a result like
Mailadress: tester@my_domain.com
Mailadress: tester@my_domain.com
Testmailadress: tester@my_domain.com

Instead I get:
Mailadress: tester@my_domain.com

Notice: Undefined variable: testmailadress in E:\admin\install\test_2.php on line 6

Notice: Undefined variable: testmailadress in E:\admin\install\test_2.php on line 7
Mailadress:
Testmailadress:

What is wrong?
Why isn't "Mailadress: tester@my_domain.com" repeated after I try to equal $_POST[mailadress] to $testmailadress in the code? Why does $_POST[mailadress] seem to disappear?

It is probably simple yet I am confused. Please help.
<?php
error_reporting(E_ALL|E_STRICT); 
ini_set('display_errors', '1');

echo "Mailadress: $_POST[mailadress]<br />";
$_POST['mailadress'] = $testmailadress; 
echo "Mailadress: $_POST[mailadress]<br />Testmailadress: $testmailadress<br />";
?>

Open in new window

0
Lennart Ericson
Asked:
Lennart Ericson
1 Solution
 
Slick812Commented:
greetings lericson,  I do not understand your code, and you are NOT consistent in calling your elements of the _POST array -
in one lile you use - $_POST[mailadress]
in another line you use - $_POST['mailadress']  // this time with the single quotes  'mailadress'
I would always use single quotes like this - $_POST['mailadress']

You should review how PHP sets a variable, it is set on the LEFT side NOT the right, you use -
$_POST['mailadress'] = $testmailadress; // incorrect

it should be -
$testmailadress = $_POST['mailadress']; // left side is SET to the right side.

I beleive this should fix your code, , ask questions if you need more information.
0
 
Lennart EricsonAmateurAuthor Commented:
Thanks, you tought me an important piece of knowledge today:
$testmailadress = $_POST['mailadress'];  is not the same as $_POST['mailadress'] = $testmailadress;
That made the trick.
Thanks so much!
0
 
Dave BaldwinFixer of ProblemsCommented:
Like Slick812 said....
<?php
error_reporting(E_ALL|E_STRICT); 
ini_set('display_errors', '1');

echo "Mailadress: $_POST['mailadress']<br />";
$testmailadress = $_POST['mailadress']
echo "Mailadress: $_POST['mailadress']<br />Testmailadress: $testmailadress<br />";
?>

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now