0
<div>
    <?php
        if (isset($_GET["error"])) {
            if ($_GET["error"] == "emptyinput") {
            ***}***
            else if ($_GET["error"] == "invaliduid") {
                echo <p>Improper username</p>;
            }
            else if ($_GET["error"] == "invalidemail") {
                echo <p>Choose a proper email</p>;
            }
            else if ($_GET["error"] == "pwdsdontmatch") {
                echo <p>Passwords do not match</p>;
            }
            else if ($_GET["error"] == "stmtfailed") {
                echo <p>Something went wrong. Try again.</p>;
            }
            else if ($_GET["error"] == "uidtaken") {
                echo <p>Username taken</p>;
            }
            else if ($_GET["error"] == "none") {
                echo <p>You are all signed up!</p>;
            }
        }
        ?>
</div>

I have bolded a character on the fifth line, which is where the error resigns. There is a syntax error that says 'syntax error, unexpected '<''. See, there is no < sign there. Thus, there is no visible way to fix the code. I am beyond confused and have tried anything and everything from removing singular <'s, to removing all of the <'s. This is a .php file and is supposed to be a signup page for a website. I have no clue what to do now. I'm lost in a code labyrinth with no map. If anyone has any idea on how to fix this, please let me know. Thank you.

David
  • 13
  • 2

3 Answers3

1

Since you are inside the php tag, your echo output should be encased in quotes:

<?php
        if (isset($_GET["error"])) {
            if ($_GET["error"] == "emptyinput") {
            }
            else if ($_GET["error"] == "invaliduid") {
                echo "<p>Improper username</p>";
            }
            else if ($_GET["error"] == "invalidemail") {
                echo "<p>Choose a proper email</p>";
            }
            else if ($_GET["error"] == "pwdsdontmatch") {
                echo "<p>Passwords do not match</p>";
            }
            else if ($_GET["error"] == "stmtfailed") {
                echo "<p>Something went wrong. Try again.</p>";
            }
            else if ($_GET["error"] == "uidtaken") {
                echo "<p>Username taken</p>";
            }
            else if ($_GET["error"] == "none") {
                echo "<p>You are all signed up!</p>";
            }
        }
?>
Rodolfo Rangel
  • 596
  • 1
  • 3
  • 15
  • I didn't know that. Thank you. I just tried it though, and the error has fallen to the closing PHP tag. It has the same error of unexpected '<'. I didn't know about the echo and the quotations though, so that will save many problems in future scipts. Thank you. – David Mar 18 '22 at 18:53
  • @David Might want to re-read the [echo](https://www.php.net/manual/en/function.echo.php) manual – brombeer Mar 18 '22 at 18:55
1

You need to make sure to wrap any < character in quotes to represent a string, for example:

Instead of:

<p>Choose a proper email</p>;

You need to write:

"<p>Choose a proper email</p>";

And so on with the rest of your strings. Another way to go about this is by closing and opening PHP tags like:

<?php
    if (isset($_GET["error"])) {
        if ($_GET["error"] == "emptyinput") {
        }
        else if ($_GET["error"] == "invaliduid") {
?>
            <p>Improper username</p>
<?php
        }
        else if ($_GET["error"] == "invalidemail") {
?>
            <p>Choose a proper email</p>
<?php
            }
        }
?>
Crisoforo Gaspar
  • 3,740
  • 2
  • 21
  • 27
0

after every echo statement put code in double or single quotes

echo"<p>Improper username</p>";