-2

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>';
?>
FirstOne
  • 6,033
  • 7
  • 26
  • 45
Xyed Xain Haider
  • 488
  • 4
  • 16
  • Let me guess. This happens when you first enters the page, but when you send the form, the `notice` disappears? (Assuming that's the code from `process.php` file) – FirstOne Jul 05 '16 at 01:47
  • bro i have tried it already
    but still this error occurs i cant get this error :(
    – Xyed Xain Haider Jul 05 '16 at 01:50
  • Look into checking whether those post variables exist before trying to use them. – Nick Jul 05 '16 at 02:06

1 Answers1

0

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>';
?>
dulaj sanjaya
  • 1,290
  • 13
  • 25
  • That will **not** fix the `notice` problem. It's still going to show that message, whether the vars are initialized or not. That's related to the form not being sent, so there is no `$_POST['fname']` to be accessed. It has nothing to do with those variables initialization. – FirstOne Jul 05 '16 at 01:55
  • no this is not the solution because i want output combing fname and ffname together and your code is returning null – Xyed Xain Haider Jul 05 '16 at 01:58
  • updated. This is working – dulaj sanjaya Jul 05 '16 at 02:18
  • All `php` lines before `$var_all =..` could be replaced with these 2: `$fname = isset($_POST['fname']) ? $_POST['fname'] : ''; $ffname = isset($_POST['ffname']) ? $_POST['ffname'] : '';` ;) – FirstOne Jul 05 '16 at 02:22