"Enter Secret Code" Form

Discussion in 'PHP' started by kemikillkv, May 7, 2009.

  1. #1
    I am a musician (also programmer/graphic designer) and we are setting up a new site to promote the record labels new "era" in music. What we are doing is releasing a free mixtape cd, and in the cd insert there will be a web link to our new website. We are also releasing 2 sets of stickers that will be handed out seperatly fromt the cds. Each sticker will have a 1 of 2 codes on it. These codes need to be entered on the site when you register in order to gain access to the site.

    Now the problem I am having, besides the fact I am a beginner in PHP, is I can't figure out how to set up the code in my registration form. I am looking for a simple add in to the login/registration system I have now. The closest thing like this I can think of is when you open a soda bottle and they have the codes you can enter on the net. I want this included on the registration page along with the registration information.

    Right now I have fields for:
    (NEED) Code 1:
    (NEED) Code 2:

    Username:
    Password:
    Email:

    The 2 codes are the same for everybody so I set up a seperate table in my DB (MySQL) called codes that contain code1, code2 with the code data already stored. So it can be checked. I just don't know how.

    Here is my register.php file I am using (LUMOS from SF.net)

    <?php
    require_once($_SERVER['../../']."lumos.php");
    
    if($_POST['register']){
        if(!$_POST['username'] || !$_POST['password'] || !$_POST['email']){
            //Make sure required fields are filled
            $msg = "Please fill in all the fields correctly and try again.<br />";
        }
        else{
            $code1 = $_POST['code1'];
            $code2 = $_POST['code2'];
            $username = $_POST['username'];
            $password = $_POST['password'];
            $email = $_POST['email'];
    
            //Check Username
            if(lumos_username_exists($username)){
                $msg = "Username already exists. Please choose another username.<br />";
            }
            else{
                //Now register
                $reg = lumos_register($username,$password);
                if(!$reg){
                    $msg = "Could not register. Please try again.<br />";
                }
                else{
                    //Then log the user in and redirect to index
                    lumos_login($username,$password);
                    header("Location: index.php");
                }
            }
    
            //Check Code1
            if(check_code1($code1)){
                $msg = "Code #1 is correct.<br />";
                    //Then log the user in and redirect to index
                    lumos_login($username,$password);
                    header("Location: index.php");
                }
            }
    
            //Check Code2
            if(check_code2($code2)){
                $msg = "Code #2 is correct.<br />";
                    //Then log the user in and redirect to index
                    lumos_login($username,$password);
                    header("Location: index.php");
                }
            }
    
        }
    }
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <meta http-equiv="Imagetoolbar" content="no">
    <title>The Seraphim Project</title>
    <style type="text/css">
    html {height:100%;}
    body {height:100%; margin:0; padding:0;}
    #bg {position:fixed; top:0; left:0; width:100%; height:100%;}
    </style>
    <style type="text/css">
    #transbox { width:350; background:#808080; filter:alpha(opacity=45); -moz-opacity:0.1; opacity:0.1; -khtml-opacity:0.1;} 
    #transbox * {position: relative;}
    #transbox div {color: #000000; font-weight:bold;} 
    </style>
    </head>
    <body>
    <div id="bg"><img src="matrixcode.png" width="100%" height="100%" alt=""></div>
    <div id="content"><p>
    <br />
    <center>
    <table align="center" bgcolor="#323232" border="4" id="transbox" width="350">
    <tr>
    <td align="center">
    <h2>
    <font size="5" color="#FFFF00">
    The Seraphim Project
    </font>
    <br />
    <font size="4" color="#FFFF00">
    Unlock the Secret
    </font>
    </h2>
    <form action="register.php" method="post">
    <div id="register">
    <font size="3" color="#FF0000">
    <hr width="95%">
    <b>
    (R) = Required&nbsp;&nbsp|&nbsp;&nbsp;(O) = Optional<br />
    </b>
    <hr width="95%">
    </font>
    <?php echo $msg; ?><br />
    <font size="3" color="#FFFFFF"><b>Secret Code #1 (R):</b></font><br />
    <input type="text" name="code1" value="<?php echo $_POST['code1']; ?>" /><br /><br />
    <font size="3" color="#FFFFFF"><b>Secret Code #2 (R):</b></font><br />
    <input type="text" name="code2" value="<?php echo $_POST['code2']; ?>" /><br /><br />
    <font size="3" color="#FFFFFF"><b>Username (R):</b></font><br />
    <input type="text" name="username" value="<?php echo $_POST['username']; ?>" /><br /><br />
    <font size="3" color="#FFFFFF"><b>Password (R):</b></font><br />
    <input type="password" name="password" /><br /><br />
    <font size="3" color="#FFFFFF"><b>E-mail (R):</b></font><br />
    <input type="text" name="email" value="<?php echo $_POST['email']; ?>" /><br /><br />
    <hr width="95%">
    <br />
    <input name="register" size="32" type="submit" value="Enter The Seraphim Project"><br />
    </div>
    </form>
    </td>
    </tr>
    </table>
    </center>
    </font>
    </p></div>
    </body>
    </html>
    Code (markup):

     
    kemikillkv, May 7, 2009 IP
  2. manzoD15

    manzoD15 Guest

    Messages:
    126
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Thanks for the useful information. Very relevant.
     
    manzoD15, May 7, 2009 IP
  3. hiteklife

    hiteklife Greenhorn

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    Haven't tested this, but I would give it a try. Put this after the require_once line. It should at least get you on the right path.

     
    hiteklife, May 8, 2009 IP