I need help with getting .php files to run in my browser (Chrome). If it's totally php, it just shows the code itself in the browser. And if it's php and html I get something like this: http://i.imgur.com/QwsRiVG.jpg
Here is the code:


// define variables and set to empty values
$name = $email = $gender = $comment = $website = "";

   $name = test_input($_POST["name"]);
   $email = test_input($_POST["email"]);
   $website = test_input($_POST["website"]);
   $comment = test_input($_POST["comment"]);
   $gender = test_input($_POST["gender"]);

function test_input($data) {
   $data = trim($data);
   $data = stripslashes($data);
   $data = htmlspecialchars($data);
   return $data;

<h2>PHP Form Validation Example</h2>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> 
   Name: <input type="text" name="name">
   E-mail: <input type="text" name="email">
   Website: <input type="text" name="website">
   Comment: <textarea name="comment" rows="5" cols="40"></textarea>
   <input type="radio" name="gender" value="female">Female
   <input type="radio" name="gender" value="male">Male
   <input type="submit" name="submit" value="Submit"> 

echo "<h2>Your Input:</h2>";
echo $name;
echo "<br>";
echo $email;
echo "<br>";
echo $website;
echo "<br>";
echo $comment;
echo "<br>";
echo $gender;


I'm sure I'm missing something obvious but we were literally just introduced to php in class.

4 Years
Discussion Span
Last Post by tapananand

Have you tested if it works??

Open http://localhost in your browser.
If it shows "It Works" do the following:
Go to xampp installation directory and find htdocs folder inside it.
Now paste the folder containing your webpages in this folder. Say folder name is "folder"
Your main file should be named index.php.
Now open in browser: http://localhost/folder/
This will execute the index.php file.
If you want to execute any other file, type in browser: http://localhost/folder/filename.php

Edited by tapananand


When an answer solves your problem be sure to :
Mark the question solved.
Upvote and comment the answer.
This just helps both the parties and keeps things interesting and healthy.

Edited by tapananand

Votes + Comments
just because, its healthy :), and you didnt tell the OP to RTFM
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.