treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] PHP page remains blank

  • Hello everyone!

    I'm having a bit of a problem with a php validation script for my login form on my webiste.

    Im sure the problem may come as simple to some of you but ive been banging my head for a few hours on it and just cant figure it out. Help would be appreciated :-)

    The login and validation work perfectly on my localhost. However, when i go to test on my remote server the validation gets stuck on the login_do page and when it should, infact, redirect me back to the page where the form is and tell me the outcome of the process. As in, were there any errors or was the registration sucessfull .

    If it helps you can go on to www.skillsden.net/register_page.php and type in a load of gibberish in the username and login fields and see for yourself.

    So, i have the following form:
    <form id="registration" action="login_do.php" method="POST">

    <li>
    <label for=name>Username</label>
    <input type="text" name="username" required placeholder="Please enter your name">
    <em>*</em>
    </li>
    <li>
    <label for=name>Password</label>
    <input type="password" name="password" required placeholder="Please enter your name">
    <em>*</em>
    </li>

    </ul>

    <p><input type="submit" value="Login" class="button" name="submit"></p>

    </form>

    Which links to login_do where simple validation is made:

    <?php 
    ob_start();
    ?>

    <?php

    if (isset($_POST["username"], $_POST["password"])){

    $username = strip_tags(htmlentities($_POST["username"]));

    $password = strip_tags(htmlentities($_POST["password"]));

    if ($username && $password){

    $connect =mysql_connect("localhost", "root", "")or die($error);
    mysql_select_db("phplogin")or die($error);

    $query = mysql_query("SELECT * FROM users WHERE username= '$username'");

    $numrows = mysql_num_rows($query);

    if ($numrows!=0){

    while($row=mysql_fetch_assoc($query)){

    $dbusername = $row ["username"];
    $dbpassword = $row ["password"];
    $activated = $row ["activated"];

    //Checks for activated email account!

    if($activated == '0')
    {

    header("location:register_page.php?status=EmailActivation");
    die();
    }

    }

    if($username == $dbusername && md5($password) == $dbpassword){

    header("Location:loginsucess.php");

    $_SESSION['username']=$user;
    }

    else
    header("location:register_page.php?status=IncorrectPasswordUsername");
    die();
    }

    else
    header("location:register_page.php?status=NoSuchUser");
    die();

    }

    else
    header("location:register_page.php?status=NoInfoGiven");
    die();
    }

    ?>


    The errors are then returned on the page where the form is - for more usability via $_GET. Code is below:

    <?php

    if(isset($_GET['status']))
    {
    if ($_GET['status'] == "EmailActivation")
    {
    echo "<span class='error'> You have not yet activated your account</span>";
    }
    if ($_GET['status'] == "IncorrectPasswordUsername")
    {
    echo "<span class='error'> Password or username is incorrect</span>";
    }
    if ($_GET['status'] == "NoSuchUser")
    {
    echo "<span class='error'>Sorry, SkillsDen couldnt find you!</span>";
    }

    if ($_GET['status'] == "NoInfoGiven")
    {
    echo "<span class='error'>Please enter you login details!</span>";
    }

    }

    ?>


    [/code]