0

I'm working on a login/registration system, but I run into this error I can't seem to figure out. Whenever I try to register, no matter what values I enter in, the page refreshes and then all of the CSS and HTML of that page just disappears. here's the code:

if ($_POST['register']) {
     if ($_POST['username'] && $_POST['password'] && $_POST['passwordconfirm'] && $_POST['fullname']) {
    $username = mysql_real_escape_string($_POST['username']);
    $password = mysql_real_escape_string(hash("sha512", $_POST['password']));
    $passwordconfirm = mysql_real_escape_string(hash("sha512", $_POST['password']));
    $fullname = my_real_escape_string($_POST['fullname']);
    if ($_POST['fullname']) {
        $name = mysql_real_escape_string(strip_tags($_POST['name']));
    };
    $check = mysql_fetch_array(mysql_query("SELECT * FROM 'users' WHERE 'Username='$username'"));
    if ($check != '0') {
        die("That username already exists! Click <a href='http://growtapians.com/Login & Register System/register.php'>here</a> and try entering a different one.");
    };
    if(!ctype_alnum($username)) {
        die("Sorry, but only numbers and letters are allowed in the username. Click <a href='http://growtapians.com/Login & Register System/register.php'>here</a> and try removing all special characters!");
    };
    if (strlen($username) > 20) {
        die("The username cannot be more than 20 characters long.  Click <a href='http://growtapians.com/Login & Register System/register.php'>here</a> and try shortening your username!");
    };
    if ($password != $passwordconfirm) {
        die("The passwords did not match! Click <a href='http://growtapians.com/Login & Register System/register.php'>here</a> and try again!");
    };
    $salt = hash("sha512", rand() . rand() . rand());
    mysql_query("INSERT INTO 'users' ('Username', 'Password', 'Name', 'Salt') VALUES ('$username', '$password', '$fullname', '$salt')");
    setcookie("c_user", hash("sha412", $username), time() + 24  * 60 * 60, "/");
    setcookie("c_salt", $salt, time() +24 * 60 * 60, "/");
    die("Registration successful!");
};
};

Here's the HTML and CSS if necessary:

<!DOCTYPE html>
        <html lang='en'>
            <head>
                <meta charset='UTF-8'>
                <meta name='viewport' content='width=device, height=device=height, initial-scale=1'>
                <style media='screen'>
            body {
                    font: 1em/1.62em verdana, sans-serif;
                    background-color: #249EC7;
            }
            form {
                    max-width: 58em; 
                    padding: .2em; 
                    margin: auto; 
                    background-color: #648cd1; 
                    color: #31d8eb; 
                    text-align: center;
            } 
            form div {
                    margin: 0em 1em 1em 1em;
            }
            form b {
                font-size: 1.3em;
            }
            form b,form input{
                    display: inline-block;
                    width: 12em;
            }
            form input {
                padding: 0.25em;
            }
            h4 a:visited {
                color: #F56433;
            }
            #logindiv {
                height: 18.5em;
                margin-top: -9.25em;
            </style>


        <body>
            <div id='logindiv' style='width: 50%; padding: 10px; border: 5px solid #316ED6; background-color: #648CD1; color: #31D8EB; margin: auto;                                   text-align: center;'>
                <h1>Login</h1>
                <br />
                <form action='' method='post'>
                    <div>
                        <b>Username:</b>
                        <input type='text' name='username' style='padding: 4px;'/>
                    </div>
                    <div>
                    <b>Password:</b>
                    <input type='password' name='password' style='padding: 4px; '/>
                        </div>
                        <div>
                            <input type='submit' value='Login' name='login'/>
                        </div>
            </form>
                <div>
                    <h4>No Account? Register <a href='register.php'>Here!</a></h4>
                </div>
            </div>
     </body>
  • 1
    For future reference, "*but I run into this error*" tells us very little. Your query is failing though, as Fred-ii- tagged as dupe, you're using single-quotes where backticks should be used. CSS is also not relevant for PHP questions (the HTML is, in this case). Last but not least, `mysql_*` functions are deprecated since PHP 5.5 (and **removed entirely** in PHP 7) and you should [stop using them](http://stackoverflow.com/q/12859942) if you can. You should choose another API that allows you to use prepared statements (which you *really should*), like `mysqli_*` or PDO. – Qirel Mar 26 '16 at 00:32
  • @Qirel I never knew I need to use backticks for SQL queries, so thanks for the answer! And about the future reference thing, I explained the error right after that. Also, I'm following a tutorial dating back 3 years back, which explains the functions. I'm quite new to mysqli functions, but I'll eventually get it! (Thanks for your comment, helped me out a lot!) – Preston Is Awesome Mar 26 '16 at 02:52

0 Answers0