I've just started coding PHP and i've stumbled on a little problem.
I'm currently just coding a simple website Register/Login project. And i'm currently on to making a "Contact us" sub.

So heres the code, if anyone could help me whats wrong:

<?php
    if (empty($name) === true || empty($email) === true || empty($message) === true)  {
       $errors[] = 'Name, email and message are required!';
    } else {
    }
    // The else above is actually not needed thus you could remove it.  
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) { $errors[] = 'That\'s not a valid email adress you have entered.'; } } if (ctype_alpha($name) === false) { $errors[] = 'Name must only contain letters!' if (empty($errors) === true); } ?>

    Are you sure you pasted the exact code? The error I get is:

    Parse error: syntax error, unexpected '}' in test.php on line 11

    since the '}' closing brace on line 11 has no matching '{' opening brace.

    Next problem I see is that the assignment statement on line 13 is never terminated (it's missing a semicolon at the end).

      This is the exact error I get:

      Parse error: syntax error, unexpected T_IF in D:\xampp3\xampp\htdocs\contact.php on line 24

      I'm gonna try ending it and see if it's gonna lead me somewhere.

        Didn't help, sadly.
        If anyone who maybe could contribute please post! Would be grateful 😉

          You'll have to show us the actual code if you want us to help with the actual problem. 😉

            Ahh! Sorry :/

            <?php
            include 'core/init.php';
            include 'includes/overall/header.php';
            if (empty($_POST) === false) {
               $errors = array();
            
            $name     = $_POST ['name'];
            $email    = $_POST ['email'];
            $message  = $_POST ['message'];
            ?>
            <?php
                if (empty($name) === true || empty($email) === true || empty($message) === true)  {
                   $errors[] = 'Name, email and message are required!';
                } else {
                }
                // The else above is actually not needed thus you could remove it.  
            if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) { $errors[] = 'That\'s not a valid email adress you have entered.'; } } if (ctype_alpha($name) === false); { $errors[] = 'Name must only contain letters!' if (empty($errors) === true);} } ?> <h1>Contact</h1> <p>Below this, you can contact the webmaster of this website.<br> If you have any questions, or you've found any bugs with the site feel free to contact me.<br> <i>Note: Answers usually take place every 24 hours, or when webmaster's computer is turned on.</p> <form action="" method="post"> <p> <?php if (empty($errors) === false) { echo '<ul>'; foreach($errors as $error) { echo '<li>', $error, '</li>'; } echo '</u>'; } ?> <label for="name">Name:</label><br> <input type="text" name="name" id="name"> </p> <p> <label for="email">Email:</label><br> <input type="text" name="email" id="email"> </p> <p> <label for "message">Message:</label><br> <textarea name="message" id="message"></textarea> </p> <p> <input type="submit" value="Submit"> </p> <?php include 'includes/overall/footer.php'; ?>

              You still have the same issue on line 23 - the assignment statement is missing a terminating semicolon.

              In addition, the closing '}' brace on line 25 has no matching opening '{' brace. Considering that the if() statement on line 24 does absolutely nothing, I'm wondering if both it and the '}' brace on that line should be removed.

              EDIT: Also note that your check for the name containing only letters is outside of the if() statement on line 4. In other words, you'll be checking the contents of $name even in cases where you haven't even defined that variable.

                I might be a dummy now. But how do I fix it if you would share?
                I get this error now, or not even an error a notice. But actully that's the only thing I need I think:

                Notice: Undefined variable: name in D:\xampp3\xampp\htdocs\contact.php on line 20

                  21 days later
                  Infected;11030313 wrote:

                  I might be a dummy now. But how do I fix it if you would share?
                  I get this error now, or not even an error a notice. But actully that's the only thing I need I think:

                  That simply means the "name" variable doesn't exist, and/or neither does $name. You have to make the variable assignment.
                  Or, maybe they exist, but not until AFTER you tried to use them. Sequencing matters.

                  Rivet`

                    Write a Reply...