Newbie need help with printing form data

Hello

I am starting out learning this php. I have made a page called

into.html

which has this in it:

[php]
First Name:


[/php]

The PHP page ActionScript.php has this in it

[php]<?php
print “Your first name is $name”;
?>[/php]

however when i run the script all i am getting on the page is:

Your first name is

the name variable that i type in is not showing?

can anyone help?

thanks

First of all you should add this to the beginning of your php scripts while developing, this will give you all errors/warnings so you don’t miss any of those :slight_smile:
[php]ini_set(‘error_reporting’, E_ALL);
ini_set(‘display_errors’, ‘1’);[/php]

into.html

  1. you should wrap POST in quotes (method=“POST”)

ActionScript.php

  1. I would change the name, ActionScript is a scripting language and it’s confusing calling it that ^^
  2. you should not end php execution (?>) if you don’t have to.
  3. you have not set the variable $name

Try this:
[php] <?php
if (!empty($_POST[‘name’])) {
echo htmlentities('Your first name is ’ . $_POST[‘name’], ENT_QUOTES, “UTF-8”);
} else {
echo ‘No name submitted’;
}[/php]

the htmlentities is to prevent xss attacks.

Thank you

Sponsor our Newsletter | Privacy Policy | Terms of Service