Register and Login (User Account System)
Posted: Sat May 26, 2012 5:20 pm
I have a problem with my register page.
If I want to register then there is nothing in the database.
I checked my code 10 times, but i see nothing wrong HELP
This is my database

init.inc.php
If I want to register then there is nothing in the database.
I checked my code 10 times, but i see nothing wrong HELP
This is my database

init.inc.php
<?php
session_start();
$exceptions = array('register', 'login');
$script_name_array = explode('/', $_SERVER['SCRIPT_NAME']);
$last_bit = end($script_name_array);
$page = substr($last_bit, 0, -4);
if (in_array($page, $exceptions) === false){
if(isset($_SESSION['gebruikersnaam']) === false){
header('Location: login.php');
die();
}
}
mysql_connect('127.0.0.1', 'root', 'toor');
mysql_select_db('db_gebruikers1');
$path = dirname(__FILE__);
include("{$path}/inc/user.inc.php");
?>
user.inc.php
<?php
// nakijken of de gebruikersnaam bestaat in de database
function user_exists($gebruiker){
$gebruiker = mysql_real_escape_string($gebruiker);
$totaal = mysql_query("SELECT COUNT(`gebruiker_id`) FROM `gebruikers` WHERE `gebruiker_naam` = '{$gebruiker}'");
return (mysql_result($totaal, 0) == '1') ? true : false;
}
// nakijken of de gebruikersnaam en wachtwoord combinatie klopt
function valid_credentials($gebruiker, $wachtwoord){
$gebruiker = mysql_real_escape_string(htmlentities($gebruiker));
$wachtwoord = sha1($wachtwoord);
$totaal = mysql_query("SELECT COUNT('gebruiker_id') FROM `gebruikers` WHERE `gebruiker_naam` = '{$gebruiker}' AND 'gebruiker_wachtwoord' = '{$wachtwoord}'");
return (mysql_result($totaal, 0) == '1') ? true : false;
}
// een gebruiker toevoegen aan de databese
function add_user($gebruiker, $wachtwoord){
$gebruiker = mysql_real_escape_string(htmlentities($gebruiker));
$wachtwoord = sha1($wachtwoord);
mysql_query("INSERT INTO `gebruikers` (`gebruiker_naam`, `gebruiker_wachtwoord`) VALUES ('{$gebruiker}, '{$wachtwoord}')");
}
?>
register.php
<?php
include('core/init.inc.php');
$errors = array();
if (isset($_POST['gebruikersnaam'], $_POST['wachtwoord'], $_POST['hhwachtwoord'])){
if (empty($_POST['gebruikersnaam'])){
$errors[] = 'Voer een gebruikersnaam in.';
}
if (empty($_POST['wachtwoord']) || empty($_POST['hhwachtwoord'])){
$errors[] = 'Voer een wachtwoord in.';
}
if ($_POST['wachtwoord'] !== $_POST['hhwachtwoord']){
$errors[] = 'Wachtwoord komt niet overeen.';
}
if (user_exists($_POST['gebruikersnaam'])){
$errors[] = 'Gebruikersnaam is al in gebruik.';
}
if (empty($errors)){
add_user($_POST['gebruikersnaam'], $_POST['wachtwoord']);
$SESSION['gebruikersnaam'] = htmlentities($_POST['gebruikersnaam']);
header('Location: protected.php');
die();
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" href="ext/css/style.css" />
<title></title>
</head>
<body>
<div>
<?php
if (empty($errors) === false){
?>
<ul>
<?php
foreach ($errors as $error){
echo "<li>{$error}</li>";
}
?>
</ul>
<?php
}
?>
</div>
<form action="" method="post">
<table>
<tr>
<td>Gebruikersnaam:</td>
<td><input type="text" name="gebruikersnaam" id="gebruikersnaam" value="<?php if (isset($_POST['gebruikersnaam'])) echo htmlentities($_POST['gebruikersnaam']); ?>" /></td>
</tr>
<tr>
<td>Wachtwoord:</td>
<td><input type="password" name="wachtwoord" id="wachtwoord" /></td>
</tr>
<tr>
<td>Herhaal wachtwoord:</td>
<td><input type="password" name="hhwachtwoord" id="hhwachtwoord" /></td>
</tr>
<td></td>
<td><input type="submit" value="Register" /></td>
</tr>
</table>
</form>
</body>
</html>