- Kod: Zaznacz cały
<?php # Register.php
// Set the page title and include the HTML header.
$page_title = 'Register';
include ('templates/header.inc');
if (isset($_POST['submit']))
{ // Handle the form.
$message = NULL; // Create an empty new variable.
// Check for a first name.
if (empty($_POST['first_name']))
{
$fn = FALSE;
$message .= '<p>You forgot to enter your first name!</p>';
} else {
$fn = $_POST['first_name'];
}
// Check for a last name.
if (empty($_POST['surname']))
{
$sur = FALSE;
$message .= '<p>You forgot to enter your surname!</p>';
} else {
$sur = $_POST['surname'];
}
// Check for an email address.
if (empty($_POST['email']))
{
$e = FALSE;
$message .= '<p>You forgot to enter your email address!</p>';
} else {
$e = $_POST['email'];
}
// Check for a password and match against the confirmed password.
if (empty($_POST['password1']))
{
$p = FALSE;
$message .= '<p>You forgot to enter your password!</p>';
} else {
if ($_POST['password1'] == $_POST['password2'])
{
$p = $_POST['password1'];
} else {
$p = FALSE;
$message .= '<p>Your password did not match the confirmed password!</p>';
}
}
if ($fn && $sur && $e && $p)
{ // If everything's OK.
// Register the user in the database.
require_once ('mysql_connect.php'); // Connect to the db.
//Sprawdzenie czy klijent juz jest zalogowany
$query = "SELECT user_id FROM user WHERE first_name='$fn' AND surname='$sur'";
$result = @mysql_query ($query);
if (mysql_num_rows($result) == 0)
{
// Make the query.
$query2 = "INSERT INTO user (first_name, surname, email, password) VALUES ('$fn', '$sur', '$e', PASSWORD('$p') )";
$result2 = @mysql_query ($query2); // the query.
if ($result2)
{ // If it ran OK.
// Send an email, if desired.
echo '<p><b>You have been registered!</b></p>';
include ('templates/footer.inc'); // Include the HTML footer.
exit(); // Quit the script.
} else { // If it did not run OK.
$message = '<p>You could not be registered due to a system error. We apologize for any inconvenience.</p><p>' . mysql_error() . '</p>';
}
} else {
$massage = '<p>That username is already taken.</p>';
}
mysql_close(); // Close the database connection.
} else {
$message .= '<p>Please try again.</p>';
}
} // End of the main Submit conditional.
// Print the message if there is one.
if (isset($message))
{
echo '<font color="red">', $message, '</font>';
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset><legend>Enter your information in the form below:</legend>
<p><b>First Name:</b> <input type="text" name="first_name" size="15" maxlength="15" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>
<p><b>Surname:</b> <input type="text" name="surname" size="30" maxlength="30" value="<?php if (isset($_POST['surname'])) echo $_POST['surname']; ?>" /></p>
<p><b>Email Address:</b> <input type="text" name="email" size="40" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /> </p>
<p><b>Password:</b> <input type="password" name="password1" size="20" maxlength="20" /></p>
<p><b>Confirm Password:</b> <input type="password" name="password2" size="20" maxlength="20" /></p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Register" /></div>
</form><!-- End of Form -->
<?php
include ('templates/footer.inc'); // Include the HTML footer.
?>
Czemu nie moge odczytac danych po podaniu hasla?? Po drugie nawet jezeli okaze sie ze uztkownik juz istnieje nie otrzymuje wiadomosci o tym a przeciez jest else { $massage = '<p>That username is already taken.</p>';} ??
2) Logowanie - nie dziala bo nie idzie odczytac poprawnie hasla. Co jest zle?? Z gory dzieki za wszelkie wskazowki.