I am really new to php but I have previous knowledge in asp.net . I have been reading and trying a lot through https://www.w3schools.com The problem is at posting forms and sending them as emails . so as a first step , I tried the following code from the following link: https://www.w3schools.com/php/php_superglobals.asp
<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Name: <input type="text" name="fname">
<input type="submit">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$name = $_POST['fname'];
if (empty($name)) {
echo "Name is empty";
} else {
echo $name;
}
}
?>
I copied it into phpDesigner8 but I got the following error when I press on run : Notice : Undefined index: REQUEST_METHOD in c:\Users\User\AppData\Local\Temp\Untitled 1 on line 10
can anyone please help me and explain to me what is wrong? Thank you much in advance !
Updated version:
<html>
<body>
<form method="post" action="">
Name: <input type="text" name="fname">
<input type="submit">
</form>
<?php
if(isset($_POST['fname'])) {
// collect value of input field
$name = $_POST['fname'];
if (empty($name)) {
echo "Name is empty";
} else {
echo $name;
}
}
?>
now there is no more error but nothing is being output to the screen with echo