1. the errors that should display, are not showing.
2. form does not seem to add new users, it just sends all the entered data into the address bar and reloads the page with empty fields. Visiting phpmyadmin shows that no users have been added.
registration.php
<?php include('core/init.inc.php'); if (isset($_POST['username'], $_POST['password'], $_POST['repeat_password'])){ if (empty($_POST['username'])){ $errors[] = 'The username field is empty'; } if (empty($_POST['password']) || empty($_POST['repeat_password'])){ $errors[] = 'The password field is empty'; } if ($_POST['password'] !== $_POST['repeat_password']){ $errors[] = 'Passwords do not match'; } if (user_exist($_POST['username'])){ $errors[] = 'The username you entered is already taken'; } if (empty($errors)){ add_user($_POST['username'], $_POST['password']); $_SESSION['username'] = htmlentities($_POST['username']); header('Location: protected.php'); die(); } } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Registration</title> <!-- Stylesheets here, before all scripts. Helps avoid styling issues. --> <link href="css/style.css" rel="stylesheet" media="screen" type="text/css" /> <link href="css/reset.css" rel="stylesheet" media="screen" type="text/css" /> <!-- If you want to use complex selectors with Cuf??load a selector engine (JavaScript framework) here. We support jQuery, Sizzle, MooTools, Dojo, Prototype and other popular frameworks. --> <script src="js/cufon-yui.js" type="text/javascript"></script> <script src="js/Opificio_400-Opificio_700.font.js" type="text/javascript"></script> <script type="text/javascript"> Cufon.replace('h1'); // Works without a selector engine Cufon.replace('#sub1'); // Requires a selector engine for IE 6-7, see above </script> </head> <body> <div class="wrapper"> <div class="loginbox"> <div class="logo"><img src="img/logo.png" class="logo"></img></div> <br><br> <div class="login"> <form action="" method"POST"> <label for="username"><h1>Username:</h1></label> <input type="text" name="username" size="27px" id="username" value="<?php if (isset($_POST['username'])) echo htmlentities($_POST['username']); ?>" /> <br><br> <label for="password"><h1>Password:</h1></label> <input type="password" name="password" size="27px" /> <br><br> <label for="repeat_password"><h1>Repeat Password:</h1></label> <input type="password" name="password" size="27px" /> <br><br> <input alt="Sign In" class="submit" id="submit" src="img/rego.png" type="image" /> </form> <div> <?php if (empty($errors) === false){ ?> <ul> <?php foreach ($errors as $error){ echo "<li>{$error}</li>"; } ?> </ul> <?php } ?> </div> </div> </div> </div> </body> </html>init.inc.php
<?php session_start(); $exceptions = array('register', 'login'); $page = substr(end(explode('/', $_SERVER['SCRIPT_NAME'])), 0, -4); if (in_array($page, $exceptions) === false) { if (isset($SESSION['username']) === false) { header('Location: login.php'); die(); } } mysql_connect('localhost','user_system',''); mysql_select_db('user_system'); $path = dirname(__FILE__); include("{$path}/inc/user.inc.php"); ?>user.inc.php
<?php //checks if the given username exists in table function user_exist($user){ $user = mysql_real_escape_string($user); $total = mysql_query("SELECT COUNT('user_id') FROM 'users' WHERE 'user_name' = '{$user}'"); return (mysql_result($total, 0) == '1') ? true : false; } //checks if the given username and password combination is valid function valid_credentials($user, $pass){ $user = mysql_real_escape_string($user); $pass = sha1($pass); $total = mysql_query("SELECT COUNT('user_id') FROM 'users' WHERE 'user_name' = '{$user}' AND ;user_password' = '{$pass}'"); return (mysql_result($total, 0) == '1') ? true : false; } //adds a user to the db function add_user($user, $pass){ $user = mysql_real_escape_string(htmlentities($user)); $pass = sha1($pass); mysql_query("INSERT INTO `users` (`user_name`,`user_password`) VALUES ('{$user}','{$pass}')"); } ?>Ive tested it without any of the styling and other html stuff, and its still the same, so im sure its got nothing to do with my design.