Witam,
Rozmyślam właśnie jak przenieść frazy z dołu skryptu (te else z errorami) nad form z rejestracją (kod HTML na górze). Pierwsze co mi przyszło do głowy to przypisanie erroru do zmiennej i jego wyświetlenie, ale szybko zrozumiałem, że tak łatwo się tego nie da zrobić (chyba..).
Szukam po prostu pomysłu/podpowiedzi jak można taki problem rozwiązać.
<?php
include("header.php");
?>
<html>
<head>
<title>Register</title>
</head>
<body>
<h1>Register</h1>
<?php
if (!isset($_SESSION['username'])) {
?>
<p>
<form action='register.php' method='POST'>
<table>
<tr>
<td>
Your full name:
</td>
<td>
<input type="text" name="fullname" />
</td>
</tr>
<tr>
<td>
Choose a username:
</td>
<td>
<input type="text" name="username" />
</td>
</tr>
<tr>
<td>
Choose a password:
</td>
<td>
<input type="password" name="password" />
</td>
</tr>
<tr>
<td>
Repeat your password:
</td>
<td>
<input type="password" name="repeatpassword" />
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Register" />
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
// Get data from the form.
$repeatpassword = strip_tags($_POST['repeatpassword']); $submit = $_POST['submit'];
// Check if form is submitted.
if ($submit) {
// Connect to database server and select database.
$namecheck = mysql_query("SELECT username FROM users WHERE username='$username'");
// Check if all data is present..
if ($username && $fullname && $password && $repeatpassword) {
// Check if username already exists.
if ($count == 0) {
// Check if passwords match.
if ($password == $repeatpassword) {
// Check the length of username and full name.
// Check the length of password.
// If everything do this...
// Encrypt passwords.
$password = md5($password); $repeatpassword = md5($repeatpassword);
// Insert user into database and show success message.
$queryreg = mysql_query("INSERT INTO users VALUES ('','$fullname','$username','$password','$date')");
die("You have been <b>registered</b>. Click <a href='index.php'>here</a> to return to login page.");
}else {echo "The lenght of password must be between 6 and 25 characters.";}
}else {echo "The username and full name cannot exceed 25 characters each.";}
}else {echo "The passwords do not match.";}
}else {echo "This user already exists.";}
}else {echo "All fields are required.";}
}
}else {
echo "You are already registered and logged in. Click <a href='members.php'>here</a> to enter the members area.<br />";
}
footer();
?>