Sir I have following codes

if(isset($_POST['button1'])) {
    $aa = $_POST['text1'];
        echo ("My name is " . $aa);


<title>First form</title>

<form name="aa" action="mix.php" method="POST">
    Name<input type="text" name="text1" value="">
    <input  type="submit" value="display" name="button1">


These codes work fine.
I am beginner so I request you to please check whether I am doing right.

Second Request:
Is it possible to use php codes in <html> tag.
if yes then please adjust my php code in html tag.

Thanks in advance

Recommended Answers

All 3 Replies

 echo $value='myname';

 Name<input type="text" name="text1" value="<?php echo $value; ?> >">

You can learn more on

There is generally no right or wrong if the code works as you intend it to. However, code could be written in more/less efficient ways, more/less readable, etc...

Is it possible to use php codes in <html> tag.

Yes, you can insert PHP within your HTML by using the open and close PHP tags. <?php. ... ?>

When the PHP page is called, the PHP engine will parse through your doc and generate the relevant HTML code that your PHP code produces.

Where would you like the phrase and name to be displayed?

Member Avatar

I would suggest having the bulk of your code above the doctype declaration (<!doctype html>) and then having the odd echo or loop or maybe a conditional in the html body. Further separation using a templating engine may help. Placing common functions (e.g. database conenction scripts) in an include file would also be an improvement. Lastly, moving towards OOP should help you reduce the amount of spaghetti coding and code duplication.

Be a part of the DaniWeb community

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