Help with this MySQL tutorial please

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

Where it does this:

    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!

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 –

CREATE TABLE coming_soon_emails 
( email VARCHAR(64) NOT NULL PRIMARY KEY
, ts    TIMESTAMP   NOT NULL DEFAULT CURRENT_TIMESTAMP
, [COLOR="Blue"]cd    VARCHAR(9)  NOT NULL
, unique_cd UNIQUE ( cd )[/COLOR]
);

as for generating your alphanumeric code values, you would do that with php

Thanks r937! Very much appreciated! :slight_smile: