this is my shash.html page

<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<form action="shash.php" method="post">

Name:<input type="text" name="username" id="username">
                        <span class="error">*<?php echo "$nameError" ; ?></span>
Password:<input type="password" name="password" id="password"><br>
Email:<input type="text" name="email" id="email"><br>
<input type="submit" name="submit" value="submit">

</form>
</body>
</html>

this is my shash.php page

<?php
$nameError="";
$name="";
if(isset($_POST['submit'])){

   if (empty($_POST["username"])) {
     $nameError = "Name is required";
   } else {


         $username=$_POST['username'];
echo $username;
   }



   }

?>

in .html page if i not fill in the Name area nd cilck submit button, it is not showing any error message like

Name is required

,it is simply redirected to .php page.i want to dispay error message in .html page itself

i wrote .php and .html code in the separate pages ,is it possible to display the $nameError in .html page??

you can't write PHP tags inside html page,
all work should be in php page.
thats how should you write the code.

<?php
$nameError="";
$name="";
if(isset($_POST['submit'])){
    if (empty($_POST["username"])) {
        $nameError = "Name is required";
    } else {
        $username=$_POST['username'];
        echo $username;
    }
}
?>
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<form action="" method="post">

    Name:<input type="text" name="username" id="username"><br/>
    <span class="error">*<?php echo "$nameError" ; ?></span><br/>
    Password:<input type="password" name="password" id="password"><br/>
    Email:<input type="text" name="email" id="email"><br/>
    <input type="submit" name="submit" value="submit">

</form>
</body>
</html>

thaks for the replay.if i wrote all complte code in single php page means iam getting the output.
my question is now, is it possible to retrive the values of php variables from one php pages to html page if i write the code in separate 2 pages?

It would be a bit unusual to do it this way but you would probably have to link to the html module (from the PHP module) with the variable as a command line parm ( module.html?parm=xxx) and then handle the variable with Javascript.

Click Here

well another roundabout way is to write the result to a file
ex.

<?php
$file = fopen("text.txt","w");
echo fwrite($file,"Hello World. Testing!");
fclose($file);
?> 

then the reult can be retrieved in an html file

 <object width="400" height="50" data="text.txt"></object> 

Odd way to do it though

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.