The ProgrammersTalk Community
Forum Register Search Today's Posts Mark Forums Read
Register

Go Back   The ProgrammersTalk Community > Web Programming > PHP


Welcome to the The ProgrammersTalk Community forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.
Reply
 
LinkBack Thread Tools    Display Modes   
  #1 (permalink)  
Old 10-17-2007, 07:01 AM
Lee's Avatar
Lee Lee is offline
PT Staff*
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: Blackpool, UK
Posts: 616
iTrader: (0)
Lee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enough
PHP register problem?

Hey,

I have a problem with my script, i had it working as far as recording the users information, now i want it to check if the user already exists, to do this i added the bits in bold, now it checks the username fine if i put a username that exists, if the user does not exist it does nothing, i just get a blank page, what could be wrong?

PHP Code:
<?php
if(isset($_POST['register'])){
$usr $_POST['usr'];
$pwd $_POST['pwd'];
$confpwd $_POST['confpwd'];
$email $_POST['email'];
$squestion $_POST['squestion'];
$sanswer $_POST['sanswer'];
$ipaddress $HTTP_SERVER_VARS['REMOTE_ADDR'];

    if(
strlen($usr) <= 16 && strlen($usr) >= && strlen($pwd) >= && $pwd == $confpwd && $email <> "" && $squestion <> "" && $sanswer <> ""){
    
    include 
'includes/config.php';
    include 
'includes/dbcon.php';

    
mysql_real_escape_string($usr);
    
mysql_real_escape_string($pwd);
    
mysql_real_escape_string($email);
    
mysql_real_escape_string($squestion);
    
mysql_real_escape_string($sanswer);

    
$pwd sha1(sha1($pwd).$pwd);
    
[
b]    $query_check "SELECT usr FROM $tbusers WHERE usr = '$usr'";
    
$result mysql_query($query_check) or die(mysql_error());
    
$rows mysql_num_rows($result) or die(mysql_error());[/b]
    
    [
b]if($row <> "0"){
        echo 
"This user already exists, please select a new username.";
    }else{[/
b]
    
        if(
$_POST['newsletter'] <> NULL){
            
$newsl "1";
        } else {
            
$newsl "0";
        }
        
        
$query "INSERT INTO $tbusers(usr, pass, email, newsletter, squestion, sanswer, ip) VALUES('$usr', '$pwd', '$email', '$newsl', '$squestion', '$answer', '$ipaddress')";
        
        
mysql_query($query) or die(mysql_error());
        
        include 
'includes/dbclose.php';
        [
b]}[/b]
    } else {
    
$error "You have the following errors:<br />";
    
        if(
strlen($usr) <= || strlen($usr) >= 17){
            
$error $error "The username must be 3 - 16 characters long.<br />";
        }
        
        if(
strlen($pwd) < 6){
            
$error $error "Your password must be at least 6 characters long.<br />";
        }
        
        if(
$pwd <> $confpwd){
            
$error $error "Your passwords do not match.<br />";
        }
        
        if(
$email == ""){
            
$error $error "You must provide an email to activate your account.<br />";
        }
        
        if(
$squestion == ""){
            
$error $error "You must provide a security question.<br />";
        }
        
        if(
$sanswer == ""){
            
$error $error "You must provide an answer to your security question.<br />";
        }
        
        echo 
"$error";
    }
    
} else {
echo 
"<form name=\"form1\" method=\"post\" action=\"\">
  Username: (3 - 16 Chars)<br />
  <input type=\"text\" name=\"usr\" id=\"usr\"><br />
  Password: (Minimum 6 Chars)<br />
  <input type=\"password\" name=\"pwd\" id=\"pwd\">
  <br />
  Confirm:(Must match password)
  <br />
  <input type=\"password\" name=\"confpwd\" id=\"confpwd\">
  <br />
  Email: (Needed to activate your account)<br />
  <input type=\"text\" name=\"email\" id=\"email\">
  <br />Security Question: (If you loose your password you will be asked this)<br />
  <input type=\"text\" name=\"squestion\" id=\"squestion\">
  <br />Security Answer:(This will be the answer you have to provide to get your password)<br />
  <input type=\"text\" name=\"sanswer\" id=\"sanswer\">
  <br />
  <input type=\"checkbox\" name=\"newsletter\" id=\"newsletter\" /> News letter
  <br />
  <input type=\"submit\" name=\"register\" id=\"register\" value=\"Register\">
  <br />
  </form>"
;
}
?>
Thanks,
Lee.

Edit: just seen the bold doesnt work inside PHP tags, so the bits i added are in the middle of (theres 3 bits)
Reply With Quote
  #2 (permalink)  
Old 10-17-2007, 01:41 PM
TeraTask's Avatar
TeraTask TeraTask is offline
PT Staff*
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 3
Join Date: Jun 2007
Location: Reno, NV
Posts: 428
iTrader: (0)
TeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enough
Probably just a typo on this line:

PHP Code:
if($row <> "0"){ 
which should be
PHP Code:
if($rows <> "0"){ 

__________________
Jeremy Miller
Content Farmer - Optimized Automated Blog Posting

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
The Following User Says Thank You to TeraTask For This Useful Post:
HelloWorld (10-17-2007)
  #3 (permalink)  
Old 10-17-2007, 01:42 PM
TeraTask's Avatar
TeraTask TeraTask is offline
PT Staff*
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 3
Join Date: Jun 2007
Location: Reno, NV
Posts: 428
iTrader: (0)
TeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enough
Oh, it looks like you have 2 else's too:

PHP Code:
    }else{[/b]
    
        if(
$_POST['newsletter'] <> NULL){
            
$newsl "1";
        } else {
            
$newsl "0";
        }
        
        
$query "INSERT INTO $tbusers(usr, pass, email, newsletter, squestion, sanswer, ip) VALUES('$usr', '$pwd', '$email', '$newsl', '$squestion', '$answer', '$ipaddress')";
        
        
mysql_query($query) or die(mysql_error());
        
        include 
'includes/dbclose.php';
        [
b]}[/b]
    } else { 

__________________
Jeremy Miller
Content Farmer - Optimized Automated Blog Posting

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
The Following User Says Thank You to TeraTask For This Useful Post:
HelloWorld (10-17-2007)
  #4 (permalink)  
Old 10-17-2007, 02:28 PM
Lee's Avatar
Lee Lee is offline
PT Staff*
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: Blackpool, UK
Posts: 616
iTrader: (0)
Lee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enoughLee will become famous soon enough
There was that spelling mistake i had tried looking for mistakes like that too lol.

I have checked the if's with else's, i make it 4 ifs with matching else's and 6 ifs on there own (which is what it should be) and it still aint working?
Reply With Quote
Reply


Thread Tools
Display Modes

   Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 12:27 PM. Powered by vBulletin
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO © 2007 ProgrammersTalk Sedo - Buy and Sell Domain Names and Websites project info: programmerstalk.net Statistics for project programmerstalk.net etracker® web controlling instead of log file analysis


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50