2

This is my code where I intend to handle the PHP form data on the same page.
However the PHP script doesn't get executed and instead all PHP code is rendered as comments when inspected.

<!DOCTYPE html>
<html>
<head></head>
<body>
<?php // php code ?>
//html code
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
    <br><br><br>
    <input type="text" required name="username" placeholder="Username" class="forminput">
    <br>
    <span><?php echo $nameErr; ?></span>
    <br>
    <input type="submit" value="Sign Up" class="forminput">
</body>
</html>

How can I execute the php script in browser? All files are in root directory.

Timothy
  • 2,004
  • 3
  • 23
  • 29
b.g
  • 411
  • 1
  • 3
  • 19
  • It might be due to the browser not being configured correctly - without more info, it's difficult to be precise.. If other php scripts work fine, then this *isnt* the answer, but if all php scripts act the same, then it probably is :) . http://stackoverflow.com/questions/14660125/how-to-enable-php-in-apache-on-linux-fedora – FreudianSlip Sep 07 '16 at 06:06
  • 2
    I hope the extension of file is .php – Danyal Sandeelo Sep 07 '16 at 06:10
  • Obviously (or maybe not) I didn't mean browser, I meant web server (apache/nginx/whatever).. sorry for any confusion. – FreudianSlip Sep 07 '16 at 06:14
  • 2
    best explanation for the problem http://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-instead-code-shows-on-the-page – JYoThI Sep 07 '16 at 06:20
  • What is the file extension ? Is it .html or .php ? – Alok Patel Sep 07 '16 at 06:20
  • Hey, apparently the ' PHP mcrypt ' module was not installed! – b.g Oct 05 '16 at 14:08

2 Answers2

3

You possibly need a XAMPP server to execute your php code even the file extension you have given as .html. If your file contain the php code it will need a web server(XAMPP) to execute the process.

Hope this tutorial will help you out with Use XAMPP to run php program

shishir
  • 851
  • 3
  • 11
  • 27
1

You can't execute PHP code in the browser. You need a server that can handle PHP. I suggest you start with an all in one LAMP stack that supports PHP out of the box.

Try this one:

XAMPP

erols
  • 83
  • 2
  • 11