0

I'm trying to update an old college project, but when I open the php files in browser all php code after -> shows on screen.

The project used to work perfectly, but now any file I open has the same issue. PHP parses until the first appearance of this (->) symbol, and from then on is rendered as text on screen.

For example, here is my connection script:

<?php
$servername = "localhost";
$username = "root";
$password = "";     //no password on mine I don't think, but sure
$dbname = "clubhousetest";

//create connection
$conn = new mysqli($servername, $username, $password, $dbname);
//check connection
if($conn->connect_error){
die("connection failed: ".$conn->connect_error);
}else{
echo "totes connected <br>";
}
?>

When opened in browser, everything after the -> in line 10

if($conn->connect_error){ 

shows as text within the webpage on screen.

I've had a look around online but cannot figure out what the problem is, and was wondering if one of you might be able to help out.

Machavity
  • 29,816
  • 26
  • 86
  • 96
derpL
  • 11
  • 3
  • Doesn't sound like it's getting passed to PHP at all. – Jonnix Sep 07 '16 at 12:06
  • which server you are using to open this file? – Amy Sep 07 '16 at 12:06
  • It should parse all or none. – Alok Patel Sep 07 '16 at 12:07
  • Check if the correct encoding is passed to the parser. It may be that `->` gets changed to `?>` – apokryfos Sep 07 '16 at 12:07
  • @Amy - I'm using wampserver, the same installation that I used when workign on the project initially. – derpL Sep 07 '16 at 12:10
  • @JonStirling, Alok Patel- Thank you. So it looks like my server isn't parsing any php for some reason? – derpL Sep 07 '16 at 12:12
  • @derpL but it should parse full or none as Alok Patel said – Amy Sep 07 '16 at 12:16
  • what phpversion()? – Thielicious Sep 07 '16 at 12:16
  • View the source of your page. I bet none of your PHP is being parsed – Machavity Sep 07 '16 at 12:19
  • Thanks for the responses guys, thanks to comments regarding parsing all or none of php I looked into whether php was running on my server (it was). Problem turned out to be user error - i was opening the files in browser by clicking on them from file explorer as opposed to opening them from localhost (php wont run in browser, runs on server only). Rusty after enjoying the holidays I guess! Thanks again, and I appreciate all of your time and effort – derpL Sep 07 '16 at 12:22

0 Answers0