I have a register.php file and I have defined $name="" inside that file
global $name;
$name = "";
and now in the html form I have:
<form name="register" action="register.php" method="post" class="smart-green">
<h1>Contact Form
<span>Registration Form</span>
</h1>
<label>
<span>Username:</span>
<input id="name" type="text" name="username" value ="<?php echo $name;?>" placeholder="Enter your user name" maxlength="20" />
</label>
</form>
But the output is <?php echo $name; ?>
instead of empty! Any idea of how I can fix this?
rename the form file to '.php' in order for php tag to be interpreted.
In a php file you can have both php and html code, but not the other way around.
Your web server will server the HTML page as is. It will only parse the HTML as best as it can. If you rename your page with a PHP extension, the web server will parse it using the PHP interpreter and that is when PHP will be interpreted. Also as Fred points out in the comments you can tell Apache to treat HTML as PHP.
That right, for the file to be recognized as php it's extension should be ex- form.php that way it can be executed to give the output