I am new to PHP and I am trying to have some code, that what a user is logged in, it will display the users name, and when they are not logged in, it will display Login/Register. I have some code, that I think should work, but it keeps displaying php on my website.
Here is the code:
<?php
$username = "Not telling";
$password = "Not telling";
$hostname = "127.0.0.1";
$dbh = mysql_connect($hostname, $username, $password) or die("Could not connect to database");
$selected = mysql_select_db("Not telling", $dbh);
$username = $_COOKIE['USER'];
$query = "SELECT name FROM Accounts WHERE username ='$username'";
$result = mysql_query($query);
$count = mysql_num_rows($result);
$name = mysql_result($result, 1);
if(isset($_COOKIE['USER'])) {
echo '<a href="">' . $name . '</a>';
}else{
echo "<a href='login.php'>Login / Register</a>";
}
mysql_close($dbh);
?>
Here is what is displayed on my website: http://prntscr.com/6rdrgj
Thanks in advance!