-1

I have this html button

<div class="test-page">
  <div class="form">
    <form class="test-form" action = 'test.php' method="get">
      <button>Run</button>
    </form>
  </div>
</div>

When i click the button i want the test.php file to run. Which displays results from a table in my local database.

<?php
$conn_array = array (
    "UID" => "username",
    "PWD" => "password",
    "Database" => "dbname",
);
$conn = sqlsrv_connect('servername', $conn_array);

if ($conn){
    echo "connected"; 
}else{
    echo "Failed";
}

$query = "select * from [Table1]";
$result = sqlsrv_query($conn,$query);

while ($row = sqlsrv_fetch_array($result)){

echo "<br>";
echo $row['Id'];
echo " ";
echo $row['Email'];
echo " ";
echo $row['Password'];

}
?>

However, when i click the button it just opens the php file. What am i missing here? I have the html and php file in htdocs folder in xamp folder. Is this the correct place? Any advice would be great. thanks!

Ryan Gadsdon
  • 2,272
  • 4
  • 31
  • 56
  • 1
    One word `AJAX`, it's too broad a topic to cover with an answer, but I suggest looking up that term in relation to PHP. If you are Ok with page reload simple submitting the form with the page as the action would work. If you don't want the reload, then you pretty much stuck with AJAX (Asynchronous JavaScript And XML) almost no one uses XML with it, so it should be `AJAJ` but that sounds weird ( J for JSON ) – ArtisticPhoenix Aug 18 '18 at 18:44
  • I am rather surprised that a ` – RiggsFolly Aug 18 '18 at 18:46

1 Answers1

1

What is missing is that your web server is not configured to feed PHP files to the PHP interpreter. Most distributions do that automatically as soon as you install the web server and the PHP interpreter for that web server. For Apache it can be a package named apache2-mod_php7 or similar. See the documentation for your distribution and your web server.

RalfFriedl
  • 1,134
  • 3
  • 11
  • 12
  • Nice catch, I miss read the question a bit. It makes more sense after reading this. `However, when i click the button it just opens the php file` I saw this as it just runs the file, not shows the code as if it were text. As you said typically that's not an issue. – ArtisticPhoenix Aug 18 '18 at 18:49