0

So, I'm trying to use a .php script to print data from a form, but everytime i try to call that script all i get is a page with the php code on it, and i can't figure out why. I don't have any errors in the code. Or at least it won't show me that i have any. Here is the code:

<DOCTYPE html>

<body>
<?php


if(isset($_POST['submit'])) 

{
    $firstName=$_POST['first'];
    
    $lastName=$_POST['last'];
    echo "Last Name: " .$lastName .$firstName . " <br />";
    $password=$_POST['pw'];
    echo "Password: " .$password . " <br />";
    $status =$_POST['status'];
    echo "Status: " .$status . "<br />";
    $waitList = $_POST['waitlist'];
    echo "Wait List: " .$waitList . "<br />";
}

?>

</body>

This is the main page code:

<!DOCTYPE html> 

<body>

<form name="register" action="process.php  " method="post" autocomplete="off" >
<p>First Name: <input type= "text" name="first" /></p>
<p>Last Name: <input type= "text" name="last" /></p>
<p>Pasword: <input type="password" name="pw"/></p>
<p>Status: 
    <input type="radio" name="status" value="enrolled" checked>Endrolled
    <input type="radio" name="status" value="notEnrolled">Not Enrolled </p>
<p><input type="checkbox" name="waitlist" value="true" checked="checked">Add me to the waiting list</p>
<p><input type="submit" name="submit" value="Sign in" /> </p>
</form> 
</body>

enter image description here

I really need some help with this, i am completly lost here..

6
  • Does your file have a .php extension? Commented Dec 24, 2020 at 10:05
  • Check that your PHP server is running. Also check that your server is configured to treat .php files (not files with other extensions) as PHP scripts. Commented Dec 24, 2020 at 10:07
  • Yes, the file is process.php Commented Dec 24, 2020 at 10:08
  • Are you running a server? May help: stackoverflow.com/questions/5121495/… Commented Dec 24, 2020 at 10:12
  • Also make sure you are cleansing your $_POST data with sanitation filters! Commented Dec 24, 2020 at 10:13

3 Answers 3

3

You have directly opened the file in the browser (you can see it from the photo), download a program like XAMPP to start a local server and view the content

Sign up to request clarification or add additional context in comments.

2 Comments

Although i needed some help with how it works, this was helpful, so thanks.
Go here download XAMPP and install, next step go to localhost folder (ex: C:\xampp\htdocs) then put your file into this folder. Now open XAMPP control panel start apache server and mysql(if you need) then open browser and put into url bar localhost/NameOfFile.php and have you finish
0

You can not access the file directly. PHP code needs to be compiled. If you are using Windows WAMP device, you will run the server and log in via http Unlike PHP, running HTML is directly on the browser so you see your HTML "code"

see: https://www.makeuseof.com/tag/how-to-set-up-your-own-wampserver/

Comments

0

you should install xammp serverenter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.