Xyed Xain Haider Xyed Xain Haider - 5 months ago 17
PHP Question

Undefined index: fname and ffname in php errors


Notice: Undefined index: fname in C:\xampp\htdocs\handleform\index.php on line 14

Notice: Undefined index: ffname in C:\xampp\htdocs\handleform\index.php on line 15


Line
14
and
15
contains

$fname = $_POST["fname"];
$ffname = $_POST["ffname"];


This is my code:

<form action="process.php" method="post">
first Name: <input type="text" name="fname" id="fname"/></br></br>
family Name: <input type="text" name="ffname" id="ffname"/></br></br>
Email: <input type="email" name="email"/></br></br>
<input type="submit" name="submit"/></br></br>
</form>

<?php
$fname = $_POST["fname"];
$ffname = $_POST["ffname"];

$var_all = $fname . " " .$ffname;

echo '<span class="label-'.$var_all .'">'.$var_all. '</span>';
?>

Answer

Updated: this is working

<!DOCTYPE html>
<html>
<body>

<form action="" method="POST">
    first Name: <input type="text" name="fname" /></br></br>
    family Name: <input type="text" name="ffname" /></br></br>
    Email: <input type="email" name="email"/></br></br>
    <input type="submit" name="submit"/></br></br>
</form>
</body>

</html>

<?php

$fname="";
$ffname="";

if(isset($_POST['fname'])){
  $fname=$_POST['fname'];
}

if(isset($_POST['ffname'])){
  $ffname=$_POST['ffname'];
}


$var_all = $fname . " " .$ffname;

echo '<span class="label-'.$var_all .'">'.$var_all. '</span>';
?>