0

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??

Edited by shashigowda

4
Contributors
4
Replies
36
Views
2 Years
Discussion Span
Last Post by edbr
0

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>

Edited by OsaMasw

0

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?

1

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

Edited by chrishea

1

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.