Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

301
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda