Jump to content

[SOLVED] Check records and match them


deepermethod

Recommended Posts

For first part see this post http://www.phpfreaks.com/forums/index.php/topic,222013.0.html

 

Now here is part 2 to my registration problem.  I got the referral check to work by username.  Now I also want to verify a referral code.  The thing is, I want to verify that the referral code matches the code from a particular member by name.

 

Here's how the referral registration works:

 

1.  Current member sends a "tell-a-friend" email to a friend to join the website.  The "tell-a-friend" form has a randomly generated string and stores the current members name and the generated string that was sent to friend in mysql.

 

2.  The friend goes to website and registers.  When registering he must enter the current members name along with the randomly generated string from the "tell-a-friend" form.

 

What I want to do is have the registration form check the database for the current member and the random string and make sure they match or are equal.  If they do, registration complete.  If they don't match, registration fails.

 

I want to search to make sure my_name (Tom) and code (5gT8Cx) exist then make sure they match.

 

Example:

 

Code: [select]

+--------+

| Field  |

+--------------+

| my_name = Tom

| code = 5gT8Cx     

| fr_emaile 

+--------------+

 

Help please.  Where you at CroNiX?

 

Thanks

Link to comment
Share on other sites

A small example.

 

<?php

  if ($_POST['submit'])) {

    // connect to db.

    $currentuser = mysql_real_escape_string($_POST['currentuser']);
    $code = mysql_real_escape_string($_POST['code']);

    $sql = "SELECT my_name, code FROM tblname WHERE my_name = '$currentuser' && code = '$code'";
    if ($result = mysql_query($sql)) {
      if (mysql_num_rows($result)) {
        // match found, do whatever.
      } else {
        echo "Match not found";
      }
    }
  }

?>

Link to comment
Share on other sites

Not sure if that works because I am getting an error before that point:

Couldn't execute code check query.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE code = 'uPkVZv'' at line 1

 

Here is the code for the above error:

$checkref = "SELECT * FROM $tbl_profiles WHERE profile_url = ".quote_smart($referral)."";
$check_ref = @mysql_query($checkref,$connection) or die("Couldn't execute referral check query.<br>".mysql_error());
if(mysql_num_rows($check_ref) < 1){
    $referral_err = "The referral name you used is not in the database.";
    $error = "1";
}

$checkrefcode = "SELECT * FROM $tbl_ref_code WHERE code = ".quote_smart($refcode)."";
$check_refcode = @mysql_query($checkrefcode,$connection) or die("Couldn't execute code check query.<br>".mysql_error());
if(mysql_num_rows($check_refcode) < 1){
    $refcode_err = "The referral code you entered is not in the database.";
    $error = "1";
}


$referralname = mysql_real_escape_string($_POST['referral']);
$referralcode = mysql_real_escape_string($_POST['refcode']);


$sql = "SELECT my_name, code FROM ref_code WHERE my_name = '$referral' && code = '$refcode'";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
// match found, do whatever.
} else {
echo "Match not found";
      }
    }

 

Any help greatly appreciated.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.