The example below shows the code I am using to test whether a user is logged in or not. If they are, then I want the code below to be removed. I managed to get the simple link to echo but when I try to echo the form my page won’t display. (Everything works in terms of checking if the user is logged etc.)
This is my first real PHP project and I’ve had a good go at working it out but I’ve this has stumped me. Any help would be much appreciated.
<?php
if (!isset($_SESSION['logged'])) {
echo '<form action='login.php' method='post' class="login">
<label for="username">Username:</label><input type='text' name='username'>
<label for="password">Password:</label><input type='password' name='password'>
<input type='submit' name='submit' value='' class="login-btn">
</form>';
echo '<a href="signup.php" class="register-btn"></a>';
}
?>
The problem is that you have syntax errors.
You end your quote at the end of
action=', and PHP doesn’t know what to do with the text,login.php. To get around this problem, use double quotes for the quotes you are trying to echo out:You can also put a
\in front of a single quote to escape it.You should also enable displaying errors on your development box, so you can see the error. (
error_reporting(E_ALL))