Det er sådan set bare 3 input-bokse. Hvis ikke de bliver valideret, kommer der en fejlmeddelelse. Hvis ingen fejl, indfør data i DB. Men jeg får hverken en "Bruger allerede i DB" besked eller en "Bruger Oprettet" besked...
Her er hele dokumentet:
--- KODE ---
<?php
ob_start();
session_start();
if (!isset( $_SESSION['adgang'])) {
header("location:index.php");
exit();
} else {
echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="
http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-store">
<meta name="robots" content="nocache" />
<title>Lager & Service Klubben</title>
<link rel="stylesheet" href="css/style.css" />
<!--[if IE]> <style type="text/css">@import "css/IE-override.css";</style>
<![endif]-->
</head>
<body>
<div id="wrapper">
<div id="container">
<img src="images/toplogo.jpg" alt="" />
<div id="menu_layer">
<ul>
<li><a href="">Nyheder</li>
<li><a href="">Skemaer</a></li>
<li><a href="">Links</a></li>
<li><a href="">Opret Administrator</a></li>
<li><a href="logout.php">Log Ud</a></li>
</ul>
</div>
<div id="input_layer">
<form name="opret" method="POST">
<p class="input_brugernavn">Brugernavn:</p>
<input type="text" name="username" maxlength="18" class="bruger_inputbox" />
<p class="input_password">Password:</p>
<input type="password" name="password" maxlength="18" class="password_inputbox" />
<p class="input_repeatpassword">Gentag Password:</p>
<input type="password" name="repeat_password" maxlength="18" class="repeatpassword_inputbox" />
<input type="submit" value="Opret" name="mysubmit" class="opret_button" />
<input type="hidden" name="submitted" value="TRUE" />
</form>';
if (isset($_POST['submitted'])) {
require_once ('mysql_connect.php');
if (!empty($_POST['username'])) {
$u = mysql_real_escape_string($_POST['username']);
} else {
echo '<p class="error_username">Indtast Brugernavn!</p>';
$u = FALSE;
}
if ( !empty( $_POST['username']) && !empty( $_POST['password'] ) && $_POST['password'] == $_POST['repeat_password'] ) {
$p = mysql_real_escape_string($_POST['password']);
} else {
echo '<p class="error_password">Password matcher ikke eller mangler!</p>';
$p = FALSE;
}
$valid_password = md5($p);
if(!isset($u) && isset($valid_password)) {
$usertable="users";
$query = "SELECT username FROM $usertable WHERE username='$u'";
$result = mysql_query($query);
if (@mysql_num_rows($result) == 1) {
echo '<p class="error_entry">Bruger allerede i DB!</p>';
} else {
mysql_query("INSERT INTO $usertable (username, password) VALUES ('$u', '$valid_password')");
echo '<p class="error_entry">Bruger oprettet!</p>';
}
}}
echo '
</div>
</div>
</div> <!-- End of Wrapper !-->
<div id="shadow_bottom"></div>
</body>
</html>';
}
?>