SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face Help with this MySQL tutorial please

    Tutorial is here: Creating a Stylish Coming Soon Page with jQuery | Tutorialzine

    Where it does this:

    PHP Code:
        15            $mysqli->query("INSERT INTO coming_soon_emails
        16                            SET email='"
    .$mysqli->real_escape_string($_POST['email'])."'");
        
    17     
        18            
    if($mysqli->affected_rows != 1){
        
    19                throw new Exception('This email already exists in the database.');
        
    20            
    Once it checks the email is not a duplicate, I would like it to add a unique (no two email records should have the same) Alphanumeric code like this: AQ4ILB9

    Then when the user gets the "Thank you!" message in the textbox, I want it to also display the unique code as above.

    I have to setup a new column in the DB for the addition of a code, correct? What properties must it have when adding to do the above code insertion? Possibly automatically creating the unique code for each record so the DB does the random code insertion work rather than a loop check in php?

    How can I display the code to the user once the "Thank you!" message is displayed.

    Any help editing the tutorial would be much appreciated!

    Thanks!

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,327
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    this thread looks awfully familiar, i've seen it somewhere else quite recently... maybe in the php forum?

    anyhow, here's how to create the table --
    Code:
    CREATE TABLE coming_soon_emails 
    ( email VARCHAR(64) NOT NULL PRIMARY KEY
    , ts    TIMESTAMP   NOT NULL DEFAULT CURRENT_TIMESTAMP
    , cd    VARCHAR(9)  NOT NULL
    , unique_cd UNIQUE ( cd )
    );
    as for generating your alphanumeric code values, you would do that with php
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks r937! Very much appreciated!


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •