0

after years I have started again with PHP and I have now a very stupid problem where I don't know how to solve it. In each php script, after '->' the code is no longer excecuted, it is just shown in the browser.

I use Apache with PHP Version 8.1.10. Is there anything I have to configure?

Example (script taken from W3):

 <?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

....
?> 

Code is only parsed until 'if ($conn->' after the -> statement, the code is visible in the browser:

Show Code in Browser

Has anyone an idea what I'm doing wrong? I have no idea anymore..

Thanks, Best regads

I tried multiple online examples, copy-pasted them 1:1, changed the browser, re-installed XAMPP.. Always the same behaivor

  • Do you have PHP installed on the server? ... and/or are serving through web server with extension PHP is set to listen for – user3783243 Nov 14 '22 at 19:12
  • Can you share your error message, please? – Maik Lowrey Nov 14 '22 at 19:15
  • Yes, PHP is installed on the sever. Everthing else is working - php is up, and also the object exists (checked with 'is_object' statement of php) – user20503622 Nov 14 '22 at 19:15
  • Did you try wrote "hello world" using PHP first to double confirm the setup is correct? – Tajul Asri Nov 14 '22 at 19:16
  • 1
  • There is no error message - therefore I have added the picture. Only the bold part of the code is executed, the other part is shown in the browser. – user20503622 Nov 14 '22 at 19:16
  • 2
    The image indicates PHP is not installed/being executed. File is `.php`? – user3783243 Nov 14 '22 at 19:17
  • Yes, it is .php. Echo in the console is working when I not include a statement with '->' – user20503622 Nov 14 '22 at 19:18
  • you will get an mysqli object if you will `print_r($conn);` – Maik Lowrey Nov 14 '22 at 19:21
  • 2
    Most likely, none of your PHP is being processed, the rest is just hiding because it's surrounded by `<>` (``). If you view the source in the browser, the rest of the PHP will be there – aynber Nov 14 '22 at 19:23
  • It was the installation - I don't know why, but after uninstall it again and install it from beginning, everything seems to be ok. Thanks for your support - stupid issue ;) – user20503622 Nov 14 '22 at 19:56
  • "Show Code in Browser" - PHP is server-side, browser should never see the code. Your script is definitively not being processed by the PHP interpreter. The browser will try really hard to parse PHP as HTML, so you may find that simple PHP code could appear to work since PHP tags and HTML both start with `<`, but there's no such thing as partial execution. – Álvaro González Nov 15 '22 at 09:39
  • The issue was that I have to start XAMPP with Admin rights. By change I did this sometimes and sometimes not. This is clearly noticed in the XAMPP console (and also in pop-ups during installation), but anyhow I had not noticed that.. Therefore it sometimes worked and sometimes not.. Thanks to Windows 11. – user20503622 Nov 15 '22 at 17:46

0 Answers0