Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

299
Views
How do i connect PHP files to HTML?

Quick Note

I'm on a fair beginner's level of web development HTML, CSS, javascript ran locally. For this, I'm using Visual Studio Code.

To The Problem

Recently I've gotten to the part where I need web server functions and database control. For this, I decided to go with XAMPP & MySQL Community Server. There have been no issues with setting this up locally.

So when I started delving into PHP coding, it's fun and I've already created a couple of files and also managed to make the PHP files connect to my database.

HOWEVER I can't seem to find one obvious way to actually connect my ".php" files to my actual main document which is the HTML document.

I might have misunderstood how PHP actually works, though to make an example to my question;

Just like you have your HTML document separated from a CSS document, at least in VS Code, you establish a connection link rel="stylesheet" href="index.css" for example, for my reasons at least to make the workspace much cleaner than bombarding the HTML document with CSS.

How do I do this with PHP files? Cause whenever I run my PHP files as they are, they work as intended, but I can't find a way to actually bind/connect them to my HTML document.

I'd love some input or a proper answer to this, and I will gladly respond with the necessary information.

Cheers :)!

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You will use html inside the php file. So instead of having an index.html, you will have an index.php file where you place all your html in there doctype, head, etc. And then inside the html you inject php code with <?php echo 'foo'; ?>

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="">
  <title></title>
  <base href="">
  <script src="script.js"></script>
  <link rel="stylesheet" href="style.css">
</head>
<body>

<h1>Some html text</h1>
<?php echo 'This is php code'; ?>

</body>
</html>
over 4 years ago · Santiago Trujillo Report

0

HTML and Javascript is Client side and PHP is Server side.

That mean you have 2 possibilities:

  1. Send data from your HTML Site to your .php

  2. Receive Data from your .php in your HTML

For Begginers:

To send data to your .php use <form> Tag This allows you to send Data to your .php file

Example:

HTML Site:

<form action="yourphpfile.php" action='post'>

Firstname <input type=text id=firstname name=name> 

Lastname <input type=text id=lastname name=lastname> 

<button type=submit> Go! </button>

</form>

Your .php file

<?php

$firstname = $_POST['firstname'];
$lastname= $_POST['lastname'];

echo("<p>Welcome " . $firstname . " " . $lastname . " </p");
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!