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?
Advertisement
Answer
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.