/    Sign up×
Community /Pin to ProfileBookmark

Can’t Login/register But No Errors

I am creating a php login and register page when i go to register using the code below, i dont get any errors but it gives me the messages: “You didn’t enter a username”, “You didn’t enter a first name” and You didn’t enter a last name.” when they have clearly been entered. Any reason why it wont read the info for these three things?

<?php

//Check if the form has been submitted
require_once(‘config.inc.php’);
$page_title = ‘Register’;
include(‘header.html’);

if(isset($_POST[‘submitted’])){

require_once(‘mysql_connect.php’);

$errors = array();//Initaliaze error away

//Check for a username
if (eregi (‘^[[:alpha:].’-] {5,15}$’, stripslashes(trim($_POST[‘username’])))){
$un = escape_data($_POST[‘username’]);
} else{
$un = FALSE;
echo ‘<p><font color =”red” size=”+1″>Please enter a username!</font></p>’;
}

//Check for a first name
if (eregi (‘^[[:alpha:].’-] {2,15}$’, stripslashes(trim($_POST[‘first_name’])))){
$fn = escape_data($_POST[‘first_name’]);
} else{
$fn = FALSE;
echo ‘<p><font color =”red” size=”+1″>Please enter your first name!</font></p>’;
}

//Check for a last name
if (eregi (‘^[[:alpha:].’-] {2,30}$’, stripslashes(trim($_POST[‘last_name’])))){
$ln = escape_data($_POST[‘last_name’]);
} else{
$ln = FALSE;
echo ‘<p><font color =”red” size=”+1″>Please enter your last name!</font></p>’;
}

//Check for an email address
if (eregi (‘^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+.[a-z]{2,4}$’, stripslashes(trim( $_POST[’email’])))){
$e = escape_data($_POST[’email’]);
} else{
$e = FALSE;
echo ‘<p><font color=”red” size=”+1″>Please enter a valid email address!</font> </p>’;
}

//Check for a password and match against the confirmed password.
if (eregi (‘^[[:alnum:]]{4,20}$’, stripslashes(trim($_POST[‘password1’])))){
if($_POST[‘password1’] == $_POST[‘password2’]) {
$p = escape_data($_POST[‘password1’]);
} else{
$p = FALSE;
echo ‘<p><font color=”red” size=”+1″>Your password did not match the confirmed password!</font></p>’;
}

} else{
$p = FALSE;
echo ‘<p><font color=”red” size=”+1″>Please enter a valid password!</font></p>’;
}

if ($un && $fn && $ln && $e && $p){ //If everything’s ok

//make sure the email address is available
$query = “SELECT user_id FROM users WHERE email=’$e'”;
$result = mysql_query ($query) or trigger_error(“Query: $queryn<br/>MySQL Error: ” . mysql_error());

if (mysql_num_rows($result) == 0) { //available

//create activation code
$a = md5(uniqid(rand(), true));

//add the user
$query = “INSERT INTO users (username, email, password, first_name, last_name, active, registration_date) VALUES (‘$un’, ‘$e’, SHA(‘$p’), ‘$fn’, ‘$ln’, ‘$a’, NOW())”;
$result = mysql_query($query) or trigger_error(“Query: $queryn<br/>MySQL Error:” . mysql_error());
if(mysql_affected_rows() == 1) {
//if it ran ok

//send the email
$body = “Thank you for registering at This IZ Jesse.com. To activate your account, please click on this link:nn”;
$body .= “http://www.thisizjesse.com/activate.php?x=”.mysql_insert_id() . “&y=$a”;
mail($_POST[’email’], ‘Registration Confirmation’, $body);

//finish the page
echo ‘<h3>Thank you for registering! A confirmation email has been sent to your address. Please click on the link in that email in order to activate your account.</h3>’;
exit();

} else{ //if it did not run ok
echo'<p><font color=”red” size=”+1″>You could not be registered due to a system error. We apologize for any inconvienience.</font></p>’;
}

} else{ //the email address is not available
echo ‘<p><font color=”red” size=”+1″>That email address has already been registered. If you have forgotten your password, use the link to have your password sent to you.</font></p>’;
}

} else{ //if one of the data tests failed.
echo ‘<p><font color=”red” size=”+1″>Please try again.</font></p>’;
}

@mysql_close(); //close db

}

?>

<h2>Register</h2>
<form action=”register.php” method=”post”>
<fieldset>

<p>Username: <input type=”text” name=”username” size=”15″ maxlength=”15″ value=”<?php
if(isset($_POST[‘username’])) echo $_POST[‘username’]; ?>” /></p>

<p>First Name: <input type=”text” name=”first_name” size=”15″ maxlength=”15″ value=”<?php
if(isset($_POST[‘first_name’])) echo $_POST[‘first_name’]; ?>” /></p>

<p>Last Name: <input type=”text” name=”last_name” size=”30″ maxlength=”30″ value=”<?php
if(isset($_POST[‘last_name’])) echo $_POST[‘last_name’]; ?>” /></p>

<p>Email Address: <input type=”text” name=”email” size=”40″ maxlength=”40″ value=”<?php
if(isset($_POST[’email’])) echo $_POST[’email’]; ?>” /></p>

<p>Password: <input type=”password” name=”password1″ size=”20″ maxlength=”20″ />
<small>Use only letter and numbers. Must be between 4 and 20 characters long.</small></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>
<input type=”hidden” name=”submitted” value=”TRUE” />
</form>
<?php
include(‘footer.html’);
?>

to post a comment
PHP

12 Comments(s)

Copy linkTweet thisAlerts:
@sstalderMay 20.2008 — What are you entering for your username in this example? Are you positive your regexp pattern is correct?
Copy linkTweet thisAlerts:
@SyCoMay 20.2008 — Can you edit your post and add the PHP /PHP tags, preferably with indentation too. Your code is pretty unreadable like that.

First this to try is print_r() the post array and see that you're getting the variables you expect after submit. Also turn up error handling. If you can't edit your ini file use error_reporting() and set it to E_ALL.

http://us.php.net/manual/en/function.error-reporting.php

Then you'll get undefined variable errors for missing variables.
Copy linkTweet thisAlerts:
@jmo99authorMay 20.2008 — im just typing in any name for the username, but the email and password work, i took out those three all together and it registered just the password and email, y do those work and not the other three?
Copy linkTweet thisAlerts:
@sstalderMay 20.2008 — Once again, give me an example of the username because I still think your regexp patters are broken.

Is there a certain criteria your trying to force your usernames to match or just letters only, 5-15 length?
Copy linkTweet thisAlerts:
@jmo99authorMay 20.2008 — i want to match the usernames, do have to do something for that? cause i just added "username" into the database, i have a "user_id" that assaigns a number but i want the username the person registered to be displayed when they login. so it could be anything "theking" or "johnnyb" whatever, but why do the first and last names not register either?
Copy linkTweet thisAlerts:
@SyCoMay 20.2008 — jmo99 I get you're new to the forum but here's a quick break down of what makes helping you easier.

[LIST]
  • [*]When someone suggests something please try it and say if it worked.

  • [*]When you post code please use the code tags. They are available in the advanced (not the quick) reply box.

  • [/LIST]


    If you provide the actual username you're trying then it can be tested with your regexp independently.

    If you post the print_r() we can see what you're getting after submit.

    If you turn up error handling you'll get the missing variable error messages, if any.

    It's a lot easier if you assume the people trying to help on the forum ask questions for a good reason and need that info to help you. Explaining in detail why we're requesting the info is time consuming.

    If you don't want to try something then that's cool too but please say so, then the person trying to help knows whats going on.

    This isn't magic ?
    Copy linkTweet thisAlerts:
    @SyCoMay 20.2008 — You say you can submit anything but you regexp is looking for a username between 5 and 15 characters that are a combination of a-z'.- followed by a space.

    Removing the space might fix it.

    Remove the ereg entirely and see if it works then you can be sure the problem is the regexp as sstalder has already suggested.

    Debug from the ground up. Remove any code that might be breaking, test and replace it until you find the problem.
    Copy linkTweet thisAlerts:
    @jmo99authorMay 21.2008 — it wasnt the space, i just dont understand why the password and email register but the others wont. I even tried the same code with the username, etc. and nothing
    Copy linkTweet thisAlerts:
    @ChazzlMay 21.2008 — I agree; I expect it is your regular expression. Can't tell from the available code.

    [code=php]eregi('^[[:alpha:].'-] {5,15}$', stripslashes( trim($_POST['username'])[/code]

    I'm still grasping the regi, so correct me if I am wrong... but to me this says the username must start with a alphabit, period, single-quote, or dash followed immediately by a space starting at character 5 and going through to character 15 which should be the end of the string.

    [code=php]<?php
    // Error Reporting
    ini_set('display_errors','On');
    error_reporting(E_ALL);
    // Includes
    require_once('config.inc.php');
    include_once('header.html');
    require_once('mysql_connect.php');
    // Definitions
    $page_title = 'Register';
    $errors = array();
    //Check if the form has been submitted
    if(isset($_POST['submitted'])){
    //Check for a username
    if ( eregi('^[[:alpha:].'-] {5,15}$', stripslashes( trim($_POST['username']) ) ) ){
    $un = escape_data($_POST['username']);
    }else{
    $un = FALSE;
    echo '<p><font color ="red" size="+1">Please enter a username!</font></p>';
    }
    //Check for a first name
    if ( eregi('^[[:alpha:].'-] {2,15}$', stripslashes( trim($_POST['first_name']) ) ) ){
    $fn = escape_data($_POST['first_name']);
    }else{
    $fn = FALSE;
    echo '<p><font color ="red" size="+1">Please enter your first name!</font></p>';
    }
    //Check for a last name
    if (eregi ('^[[:alpha:].'-] {2,30}$', stripslashes(trim($_POST['last_name'])))){
    $ln = escape_data($_POST['last_name']);
    } else{
    $ln = FALSE;
    echo '<p><font color ="red" size="+1">Please enter your last name!</font></p>';
    }
    //Check for an email address
    if (eregi ('^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+.[a-z]{2,4}$', stripslashes(trim( $_POST['email'])))){
    $e = escape_data($_POST['email']);
    }else{
    $e = FALSE;
    echo '<p><font color="red" size="+1">Please enter a valid email address!</font> </p>';
    }
    //Check for a password and match against the confirmed password.
    if (eregi ('^[[:alnum:]]{4,20}$', stripslashes(trim($_POST['password1'])))){
    if($_POST['password1'] == $_POST['password2']) {
    $p = escape_data($_POST['password1']);
    } else{
    $p = FALSE;
    echo '<p><font color="red" size="+1">Your password did not match the confirmed password!</font></p>';
    }
    } else{
    $p = FALSE;
    echo '<p><font color="red" size="+1">Please enter a valid password!</font></p>';
    }
    if ($un && $fn && $ln && $e && $p){ //If everything's ok
    //make sure the email address is available
    $query = "SELECT user_id FROM users WHERE email='$e'";
    $result = mysql_query ($query) or trigger_error("Query: $queryn<br/>MySQL Error: " . mysql_error());
    if (mysql_num_rows($result) == 0){ //available
    //create activation code
    $a = md5(uniqid(rand(), true));
    //add the user
    $query = "
    INSERT INTO
    users (username, email, password, first_name, last_name, active, registration_date)
    VALUES
    ('$un', '$e', SHA('$p'), '$fn', '$ln', '$a', NOW())
    ";
    $result = mysql_query($query) or trigger_error("Query: $queryn<br/>MySQL Error:" . mysql_error());
    if(mysql_affected_rows() == 1){
    //if it ran ok, send the email
    $body = "Thank you for registering at This IZ Jesse.com. To activate your account, please click on this link:nn";
    $body .= "http://www.thisizjesse.com/activate.php?x=".mysql_insert_id() . "&y=$a";
    mail($_POST['email'], 'Registration Confirmation', $body);
    //finish the page
    echo '<h3>Thank you for registering! A confirmation email has been sent to your address. Please click on the link in that email in order to activate your account.</h3>';
    exit();
    } else{ //if it did not run ok
    echo'<p><font color="red" size="+1">You could not be registered due to a system error. We apologize for any inconvienience.</font></p>';
    }
    } else{ //the email address is not available
    echo '<p><font color="red" size="+1">That email address has already been registered. If you have forgotten your password, use the link to have your password sent to you.</font></p>';
    }
    } else{ //if one of the data tests failed.
    echo '<p><font color="red" size="+1">Please try again.</font></p>';
    }
    @mysql_close(); //close db
    }
    ?>
    <html>
    <head>
    <title>Can't Login/register But No Errors </title>
    </head>
    <body>
    <h2>Register</h2>
    <form action="register.php" method="post">
    <fieldset>
    <p>
    Username: <input type="text" name="username" size="15" maxlength="15" value="<?php if(isset($_POST['username'])) echo $_POST['username']; ?>" />
    </p>
    <p>
    First Name: <input type="text" name="first_name" size="15" maxlength="15" value="<?php if(isset($_POST['first_name'])) echo $_POST['first_name']; ?>" />
    </p>
    <p>
    Last Name: <input type="text" name="last_name" size="30" maxlength="30" value="<?php if(isset($_POST['last_name'])) echo $_POST['last_name']; ?>" />
    </p>
    <p>
    Email Address: <input type="text" name="email" size="40" maxlength="40" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>" />
    </p>
    <p>
    Password: <input type="password" name="password1" size="20" maxlength="20" />
    <small>Use only letter and numbers. Must be between 4 and 20 characters long.</small>
    </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>
    <input type="hidden" name="submitted" value="TRUE" />
    </form>
    <?php
    include('footer.html');
    ?>
    </body>
    </html>[/code]
    Copy linkTweet thisAlerts:
    @jmo99authorMay 21.2008 — already i got it, no thanks to SyCo, and i am new to the forum. could it have been the joined "may 2008" in the right corner? i dont know maybe?

    i know your a "bad ass computer programmer" but learn to talk to people


    it isnt magic?
    Copy linkTweet thisAlerts:
    @sstalderMay 21.2008 — SyCo actually had all good points for [I]anyone[/I] that is new to the forum, including yourself. I asked you a simple question because I felt it was key to helping you solve your issues but rather than answer my question you simply restated your first question again in your reply and told us something we already knew based on your first reply, which did not help us at all.

    We may ask you some questions that make you think "Well, why is he asking such a stupid question?" - well to be honest, most of the time the mistakes you make in the learning process are extremely dumb and everyone makes them so we narrow those out first. It doesn't mean we are degrading you in any way or we think you are an idiot so we post something to take up space, we are only trying to help.

    Ok sorry that was so long, but I felt it had to be said.

    Anyhow, is your problem solved now? and can you please share the issue so everyone can sleep better tonight?
    Copy linkTweet thisAlerts:
    @ChazzlMay 21.2008 — Can you share your solution so that other people with similar problems might find a fix to their code too? I'm sure they will be grateful ^.^
    ×

    Success!

    Help @jmo99 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.25,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...