Christos Michael Christos Michael - 1 month ago 23
PHP Question

echo my form values on php

Am using the code below in order to print the values that am inserting on the boxes. However After I put the values and click submit nothing is printing out.


<form action="<?php $_SERVER['PHP_SELF']?>" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">

if(isset($_POST["submit"])) {
$name = filter_input(INPUT_POST, 'name');
$email = $_POST['email'];
echo $name;
echo $email;


About below I tried both cases because on the simple one $_POST['email'] I was getting a warning:

$name = filter_input(INPUT_POST, 'name');
$email = $_POST['email'];


Do not Access Superglobal $_POST Array Directly

I am using Netbeans IDE 8.2.


This is never set:

if (isset($_POST["submit"])) {

Instead change it to:

if (count($_POST) > 0) {

You don't have any elements matching name="submit". Also, it is a bad practise to use isset($_POST["submit"]) as many of us, won't name it.

If you want to check for specific things set, like in your case, you need to do:

if (count($_POST) > 0 && isset($_POST["name"]) && isset($_POST['email'])) {

If still you wanna make your code work with the above set-up, kindly add a name and value here:

<input type="submit" name="submit" value="Submit" />