-1

What I'm trying to do is get my html/php code to display data from my MySQL in a table.
It connects just find to the database, but I think I'm getting an error at: $resultt=$con->query("SELECT DisplayName, Kills, Deaths, Wins, Lost FROM TTPlayer"); for it always shows that code as text on the webpage when I execute it. Also in the tables it shows each of the row methods and their variable

Thanks in advance for any help!

Code: http://pastebin.com/j1EDux5y

Executed webpage: http://pasteboard.co/2pzqESnw.png

ZachtheBoB
  • 398
  • 3
  • 10
  • 1
    The answer is simple but can be because of many factors. Is the file `.php` extension? Is a webserver installed? If so, how are you accessing it, `http://localhost/file.php` or `file:///file.php`? – Funk Forty Niner Apr 08 '15 at 12:25
  • execute the `.php` file via webserver, make sure `php5_module` is enabled, ensure that you are not using `` short tags – mysqlrockstar Apr 08 '15 at 12:30
  • It is a .html file, I will check on php5_module – ZachtheBoB Apr 08 '15 at 12:32
  • On `.html` you cannot execute php, On `.php` you can execute html :-) – mysqlrockstar Apr 08 '15 at 12:35
  • 1
    That's wrong @MySQLRockstar, PHP can be executed in HTML files. See Fred -ii-'s answer below. – Jay Blanchard Apr 08 '15 at 13:00
  • @Jay Blanchard, By default we can never do that, forefully we can do if we modify .htaccess. But why unnecessary, when .php is already there. For your reference http://stackoverflow.com/questions/11312316/how-do-i-add-php-code-to-html-files – mysqlrockstar Apr 08 '15 at 13:35

1 Answers1

2

"It is a .html file, I will check on php5_module – ZachtheBoB 2 mins ago"

.html file extensions will not parse PHP directives.

A .php extension is required to do this, plus making sure a webserver and PHP are installed and properly configured.

If on a local machine, you will need to access it like http://localhost/file.php and not file:///file.php

You can however, instruct Apache to treat .html files as PHP through .htaccess if that is your preference.

AddType application/x-httpd-php .html

If you only plan on including the PHP on one page, it is better to setup this way:

<Files yourpage.html>
AddType application/x-httpd-php .html
</Files>

If you are running PHP as CGI

AddHandler application/x-httpd-php .html

If on GoDaddy

Options +ExecCGI
AddType application/x-httpd-php .php .html
AddHandler x-httpd-php5 .php .html
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141