Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 09-20-2005, 08:47 AM mysql_num_rows
Experienced Talker

Posts: 34
Trades: 0
I have a register script, which (Before adding a new account to the database) looks to make sure that the user's email address has not already been previously entered. Here it is:

PHP Code:
//checks for an account with the same email address
$sql mysql_query("SELECT email FROM iusers WHERE email='$encryptemail'") or die(mysql_error()); 
$num_records mysql_num_rows($sql);
if (
$num_records 0) {
    
header ("Location: ../content/register.php?overallerr=1&firstname=" $firstname "&lastname=" $lastname "&email=" $email);
}


//inserts data into database
$query1 "INSERT INTO iusers........ etc 
Currently, it doesn't work. I can't find anything wrong with it. I can sign up with the same email address multiple times. (E.G. Even though $num_records should be greater than 0, it doesn't seem to be going into that IF statement.)

That header line should take the user back to the register page, and asks the user to input a different address. I tried to find out exactly what was happening, so I "echoed" the $num_records variable after the IF statement. Here's what it looks like now:

PHP Code:

//checks for an account with the same email address
$sql mysql_query("SELECT email FROM iusers WHERE email='$encryptemail'") or die(mysql_error()); 
$num_records mysql_num_rows($sql);
if (
$num_records 0) {
    
header ("Location: ../content/register.php?overallerr=1&firstname=" $firstname "&lastname=" $lastname "&email=" $email);
}

echo (
$num_records);
//inserts data into database
$query1 "INSERT INTO iusers........ etc 
When that echo statement is in there, the script works fine... The IF statement works, and I'm sent back to the register page. WHY? I didn't change anything important. When I delete the echo statement, the script stops working.

I'd keep it in there, but I have a header statement at the end of the script....

Thanks for any help you can provide,

Andrew
mtairhead is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-20-2005, 10:04 AM
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
Code:
$sql = "select username, password from users where username = {$_POST['_username']} and password={$_POST['_password']}";

$result = Execute($sql);

if($result->EOF){
  // No record proceed
  // New member
  // Add details
}else{
  // Reject user exists
}
Try putting an else at the end of

Code:
 if ($num_records > 0) {
    header ("Location: ../content/register.php?overallerr=1&firstname=" . $firstname . "&lastname=" . $lastname . "&email=" . $email);
  exit;
} else{
  $query1 = "INSERT INTO iusers ...
}
Always call exit after a redirect to prevent strange stuff from happening. Also use if else to make your page work how you want it to.

But you should be able to get away with a select for that user, if it returns null then you can safely add the new one.

Ibbo
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Reply     « Reply to mysql_num_rows
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10384 seconds with 12 queries