-4

I want to submit some form information using POST method. On submit i want to verify those choises with a php file. I have the following code

<?php
$name = $_POST["name"];

echo "<h2>Your Choices:</h2>";
echo "<table class=\".2\">
        <tr>
            <td>Name:</td>
            <td>$name</td>
        </tr>

        </table>";
?>

The problem is that when i submit the form, the php file loads perfect, but the variables value ($name) is not visible. The tale just shows $name as text.

What am i doing wrong? i've tried many variations, using .$name. etc but nothing works...

Thanks

aynber
  • 22,380
  • 8
  • 50
  • 63
ParisL
  • 1
  • 1
  • 6

2 Answers2

0

As I can assume, your code just display <td>$name</td> instead of variable value.

You can use variables in this way:

echo("<td>" . $var . "</td>")
aso
  • 1,331
  • 4
  • 14
  • 29
  • 1
    Why would you assume that? (What does assuming do?) Have you tested the OP's code? `echo` does not need parentheses and all variables are interpolated in double quotes. Read the code in the original question again - the variable will work perfectly in this situation as long as it is not empty. The OP actually has *another* problem. – Jay Blanchard Feb 09 '16 at 18:45
0

As mentioned by others, the $_POST values may be not correct. I would change the code to dump the POST values, and simply echo the one value in your code, e.g.

<?php
print_r($_POST);
$name = $_POST["name"];
?>
<h2>Your Choices:</h2>
<table class=".2">
        <tr>
            <td>Name:</td>
            <td><?= $name ?></td>
        </tr>
</table>

Obviously you'll want to remove that print_r once you have solved the problem.

CharlieH
  • 1,432
  • 2
  • 12
  • 19