Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Join! button does not jump to correct location/pgae

Status
Not open for further replies.

mesafloyd

Technical User
Aug 19, 2006
31
US
Hello, I have a php login script I found on evolt. For the most part works very well. I have made several successful mods, but I have a problem I just cannot solve, been working on this one issue for 2-3 weeks, Im not a real programmer so pleae be gentle

The register pages has 6 fields. Three are empty for the user to fill out, the other 3 are autofilled. When the user fills the 3fields then hits the Join! button the username, password and email DOES properly register to the mysql database, but the screen to the user, does not indicate to the user that He is now registered, the programs just seems to jump over that part.. the screen puts up the original 'Register' screen again with the 3 fields emptied.

IB stumpted .... any help would be very much appreciated.

Here is the code. Thanks in advance for any help.

Code:
<?php

session_start();
include ("database.php");

/**
 * Returns true if the username has been taken
 * by another user, false otherwise.
 */
function usernameTaken($username)
{
    global $conn;
    if (!get_magic_quotes_gpc())
    {
        $username = addslashes($username);
    }
    $q = "select username from users where username = '$username'";
    $result = mysql_query($q, $conn);
    $num = mysql_numrows($result);
    return $num;
}

/**
 * Inserts the given (username, password) pair
 * into the database. Returns true on success,
 * false otherwise.
 */
function addNewUser($username, $password, $pcidip, $datetime, $email, $emailchk)
{
    global $conn;
    $q = "INSERT INTO users VALUES ('$username', '$password', '$pcidip', '$datetime', '$email', '$emailchk')";
    $query = mysql_query($q, $conn);
return $query;
}

////////This is where my problem is <I think> ...
////////When I press Join! button, the routine adds the new user to db OK but
/////// instead of going to the "Registered! Thank you.." below it empties the 3 fields(user,pass,email) and starts again
/////// asking you to register<again>. The user gets no indication that he was registered.

/**
 * Displays the appropriate message to the user
 * after the registration attempt. It displays a
 * success or failure status depending on a
 * session variable set during registration.
 */
function displayStatus()
{
    $uname = $_SESSION['reguname'];
    if ($_SESSION['regresult'])
    {

?>

<h1>Registered!</h1>
<p>Thank you.. <br>
Your information has been added to the database, you may now <a href="index.php" title="Login">log in</a></p>

<?
    }
    else
    {
?>

<h1>Registration Failed</h1>
<p>We're sorry, but an error has occurred and your registration for the username <b><? echo
$uname; ?></b>, could not be completed.<br>
Please try again at a later time.</p>

<?
    }
    $_SESSION['reguname'] = NULL;
    $_SESSION['registered'] = NULL;
    $_SESSION['regresult'] = NULL;
}

if (isset($_SESSION['registered']))
{
    /**
     * This is the page that will be displayed after the
     * registration has been attempted.
     */
?>

<html>
<title>Registration Page</title>
<body>

<?php displayStatus(); ?>

</body>
</html>

<?
    return;
}

/**
 * Determines whether or not to show to sign-up form
 * based on whether the form has been submitted, if it
 * has, check the database for consistency and create
 * the new account.
 */
if (isset($_POST['subjoin']))
{
    /* Make sure all fields were entered */
    if (!$_POST['user'] || !$_POST['pass'])
    {
        die('You didn\'t fill in a required field.');
    }

    /* FKadded this -- checks that email field has characters */
    if (!$_POST['email'])
    {
        die('You didn\'t fill in the email field, silly');
    }


    /* Spruce up username, check length */
    $_POST['user'] = trim($_POST['user']);
    if (strlen($_POST['user']) > 30)
    {
        die("Sorry, the username is longer than 30 characters, please shorten it.");
    }

    /* Check if username is already in use */
    if (usernameTaken($_POST['user']))
    {
        $use = $_POST['user'];
        die("Sorry, the username: <strong>$use</strong> is already taken, please pick another one.");
    }

    /* Add the new account to the database */
    $password = ($_POST['pass']);//FK removed md5.. was... $md5pass = md5($_POST['pass']);
    $_SESSION['reguname'] = $_POST['user'];
    $_SESSION['regresult'] = addNewUser($_POST['user'], $password, $pcidip, $datetime,
        $email, $emailchk);//FK-added $pcidip...$emailchk
    $_SESSION['registered'] = true;
    echo "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\">";
    return;
}
else
{
    /**
     * This is the page with the sign-up form, the names
     * of the input fields are important and should not
     * be changed.
     */
?>

<html>
<title>Registration Page</title>
<body>
<h1>Register</h1>
<form action="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr>
<tr><td>Email Addr:</td><td><input type="text" name="email" maxlength="50"></td></tr>
<tr><td>Send Email Alerts:</td><td> <input type="checkbox" name="emailchk" value="1" checked></td></tr><br />

<!-- FKinsert begins here -->
<tr><td>Your IP for this visit:</td><td> <input name="pcidip" type="text" value="
<?php echo $_SERVER['REMOTE_ADDR']; ?>" size="20"></td></tr><br />

<tr><td>Date-Time for this visit:</td><td> <input name="datetime" type="text" value="
<?php echo date("Y.m.d - h:i:s"); ?>" size="20"></td></tr><br>
<!-- FK insert ends here -->

<tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Join!"></td></tr>
</table>
</form>
</body>
</html>

<?
}
?>

Thanks in advance for any help... I am a rookie at programming(old hardware guy)
Floyd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top