Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6829643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:31:28+00:00 2026-05-26T22:31:28+00:00

I want to implement a new system for referal/promotions. my new system where when

  • 0

I want to implement a new system for referal/promotions. my new system where when a user register a specific source is assig to him. A source can be anything from referal (clients domain) and a promotion code (eg: 50% off). This source also have a date (y-m-d). Each source id is unique and multiple users can have the same source id

For example:

source id : 1 = www.domain1.com / 2011-11-20 / (empty referal code) 
source id : 2 = www.domain1.com / 2011-11-20 / referalcode1
source id : 3 = www.domain2.com / 2011-11-20 / referalcode1
source id : 4 = www.domain2.com / 2011-11-20 / referalcode2

The referal code can be mixed from client1 to client 2

How can i make sure when someone register (its free registration and we have over 1000 per hours now) we dont have duplicate records and risk the mysql to generate errors?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:31:28+00:00Added an answer on May 26, 2026 at 10:31 pm

    From mysql page:

    The main idea is to insert records using the ignore statement. If
    you use the IGNORE keyword, errors that occur while executing the
    INSERT statement are treated as warnings instead. For example, without
    IGNORE, a row that duplicates an existing UNIQUE index or PRIMARY KEY
    value in the table causes a duplicate-key error and the statement is
    aborted. With IGNORE, the row still is not inserted, but no error is
    issued. Then retrieve the last ID using mysql_insert_id

    If the record does not exists, it will insert it and the last ID will be returned.

    Now, if there’s not record returned, you can do your select. This means a record already exists, so simply use it.

    Example:

    // make sure $id is safe (preventing sql injections)
    $sql = "INSERT IGNORE INTO yourtable SET `field1` = 'value1' ... "; 
    mysql_query($sql);
    
    if(mysql_affected_rows() == 1) { // no record found and then the inserts worked
      $id = mysql_insert_id(); // id from the primary key
      // add to cache
    }
    else {
      // you can also cache them when they were inserted (faster to run than a select statement)
      $id = retreiveFromCache($field1, $field2 /* etc...*/);
      if(!$id) { // no record found in cache
        // now the select can be done using the fields received
        // make sure your use the right index otherwise it can be slow
        $sql = "SELECT id FROM promotions_referrals WHERE `field1` = 'value1' ... "; // 
        $query = mysql_query($sql);
        $row = mysql_fetch_assoc($query);
        $id = $row['id'];
        // add to cache
      }
    }
    

    At this point you will have $id assigned and you are sure there’s no duplicate/mysql errors.

    Note: if a domain belongs to one client, use the client id instead of using the domain. This way you will use INT as index which is faster than VARCHAR. Same idea for referral code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement a workflow system on a new website which i am
I want to implement DnD on my system by dragging a node from a
I am new to matlab and I want to implement the fast KL transform.
I want to implement a java.util.Comparator with Long : new Comparator<Long>() { public int
I am new to iPhone developer, I want to implement different Animations on button
I want to implement an application which will work as a parser. User will
I want to implement my own dynamic memory management system in order to add
I want to implement the following scenario: When a user presses the Home key
Iam new to bash script programming. I want to implement a bash script deploymLog
I want to implement an aplication where I have various Objects that can be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.