Reputation: 1669
I am trying to run this simple php code (in a file named "database.php")
<html>
<head>
</head>
<body>
<?php
$servername = 'localhost';
$username = 'admin';
$password = 'admin1';
//Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die('Connection failed: ' . $conn->connect_error);
}
else {
echo 'Connected Successfully.' ;
}
$conn->close();
?>
</body>
</html>
AND HERE IS THE OUTPUT IN MY BROWSER
connect_error)
{ die('Connection failed: ' . $conn->connect_error); }
else { echo 'Connected Successfully.' ; }
$conn->close();
?>
( the first part of php code get processed but later it shows just the source code)
PLEASE HELP.
Upvotes: 0
Views: 88
Reputation: 1110
The first part of the code is not actually being processed, but being hidden because the browser thinks it is an HTML tag. So everything between <?
and ->
gets hidden. A viktike points out, you need to enable PHP parsing by your server, which may require additionally a number of actions beyond simply adding PHP handing in the sercver config.
I'm not familiar with Wamp, but it seems like PHP has been disabled so I'd explore re-enabling, starting with simply restarting the server, and then looking at Apache config and Wamp's own method of configuring things which probably departs from standard method of doing this stuff.
Upvotes: 0
Reputation: 733
Set a handler for *.php files in the webserver config. For apache:
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Upvotes: 1