0
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
    <title>MechRook</title>
    <link type="text/css" rel="stylesheet" href="css.css"/>
    <link type="image/jpeg" rel="short icon" href="favicon.jpg"/>
</head>
<body>
    <div id="fheader">
        <h1>Account</br></h1>
        <?php
        $form = '<form method="post" action="index.php">
            Username: <input name="user" type="text"></br>
            Password: <input name="pass" type="password"></br>
            <input name="btn" type="submit" value="Login">
        </form>';
        if ($_POST['btn']) {
            $user = $_POST['user'];
            $pass = $_POST['pass'];

            if ($user) {
                if($pass) {
                    echo "$user - $pass <hr> $form";
                }
                else {
                    echo "You must enter your password. $form";
            }
            else {
                echo "You must enter your username. $form";
            }   
        }
        else {
            echo $form;
        }
        ?>
        <h2>Account:</br><?php echo $_POST['user']; ?></h2>
    </div>
    <div id="sheader">
        <h1 style="font-size:50px">MechRook</h1>
        <section id="con">
            <div class="button">
                <a href="index.html" class="link">Home</a>
            </div>
            <div class="button">
                <a href="account.html" class="link" style="font-size:15px">Account</a>
            </div>
            <div class="button">
                <a href="contact.html" class="link">Contact</a>
            </div>
        </section>
        <h2>
            </br></br>Welcome to MechRook
        </h2>
        <p>
            Welcome to MechRook! MechRook is currently nothing. Wow what a waste of a URl, you might think that but you will see. My friends and I have big plans for MechRook. We have multiple designers for website templates and coders.
        </p>
    </div>
</body>
</html>

It gives me a 500 ERROR. I am trying to make a form! Please Help! Tell me what I can do. Thanks!________________________________________________________________________________________________________________

Kyle Pfromer
  • 1,485
  • 1
  • 15
  • 26
  • 2
    1. [Enable error reporting](http://stackoverflow.com/a/6575502/1438393) and see if it changes anything. 2. Check your server logs. – Amal Murali Apr 18 '14 at 16:41
  • 3
    You're missing a closing brace (`}`) after this statement: `echo "You must enter your username. $form";`. – Amal Murali Apr 18 '14 at 16:42
  • Wait What I think I fixed it and it still gives me a error:Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator to inform of the time the error occurred and of anything you might have done that may have caused the error. More information about this error may be available in the server error log. Web Server at mechrook.com – Kyle Pfromer Apr 18 '14 at 16:47

2 Answers2

1

I'm not a PHP programmer (I do JS, and I'm relatively new at it), but right away I see you're missing a closing bracket. The page will display with this code:

if ($_POST['btn']) {
        $user = $_POST['user'];
        $pass = $_POST['pass'];

        if ($user) {
            if($pass) {
                echo "$user - $pass <hr> $form";
            } else {
                echo "You must enter your password. $form";
            }
        } else {
            echo "You must enter your username. $form";
        }   
    } else {
        echo $form;
    }
Justin
  • 1,341
  • 11
  • 24
  • What's not working? Here's a fiddle of your code with the closing bracket added: http://jsfiddle.net/y67Z5/ Are you testing on a server that can interpret PHP? – Justin Apr 18 '14 at 17:05
1

I tested in at a server after adding the missing bracket, it works fine so just try this new code (it doesn't have messy if-else conditions):

<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
    <title>MechRook</title>
    <link type="text/css" rel="stylesheet" href="css.css"/>
    <link type="image/jpeg" rel="short icon" href="favicon.jpg"/>
</head>
<body>
    <div id="fheader">
        <h1>Account</br></h1>
        <?php
        $form = '<form method="post" action="'.$_SERVER['PHP_SELF'].'">
            Username: <input name="user" type="text"></br>
            Password: <input name="pass" type="password"></br>
            <input name="btn" type="submit" value="Login">
        </form>';
        if ($_POST['btn']) {
            $user = $_POST['user'];
            $pass = $_POST['pass'];

            if (($user) && !($pass)) {
                echo "You must enter your password. $form";
            }
            else if (!($user) && ($pass)) {
                echo "You must enter your username. $form";
            }
            else if (!($user) && !($pass)){
                echo "You must enter your username and your password. $form";
            }
            else {
                echo "$user - $pass <hr> $form";
            }

        }
        else {
            echo $form;
        }
        ?>
        <h2>Account:</br><?php echo $_POST['user']; ?></h2>
    </div>
    <div id="sheader">
        <h1 style="font-size:50px">MechRook</h1>
        <section id="con">
            <div class="button">
                <a href="index.html" class="link">Home</a>
            </div>
            <div class="button">
                <a href="account.html" class="link" style="font-size:15px">Account</a>
            </div>
            <div class="button">
                <a href="contact.html" class="link">Contact</a>
            </div>
        </section>
        <h2>
            </br></br>Welcome to MechRook
        </h2>
        <p>
            Welcome to MechRook! MechRook is currently nothing. Wow what a waste of a URl, you might think that but you will see. My friends and I have big plans for MechRook. We have multiple designers for website templates and coders.
        </p>
    </div>
</body>
</html>

Hope it works.

Anay Karnik
  • 920
  • 1
  • 7
  • 15