Page 1 of 1

Sign-Up Form help/suggestion

Posted: Tue Jul 22, 2008 1:19 pm
by Draygon
I am trying to create a form for a campaign for a game mod that I am helping work with, this is the sign up form. I will do my best to explain what is going on in it so that you can hopefully give me some good feedback.

Basically I have created a table that looks like this.

Code: Select all

CREATE TABLE users(faction CHAR(6) NOT NULL, time_zone CHAR (13) NOT NULL, division1 CHAR (15) NOT NULL, division2 CHAR(15) NOT NULL, division3 CHAR (15) NOT NULL, doctrine CHAR(15) NOT NULL, name CHAR(16) NOT NULL, PRIMARY KEY (name);
So on this form they enter a name they want used for their profile, they select a faction type (axis or allies) and then in each faction there are 3 doctrines to choose from. Once they choose the faction/doctrine then they select their choice of doctrine. There are 6 divisions for each faction.

I have it so that all of the selecting will be done using arrays and drop down menu's. and then at the end sending all the data to the table.

One part I havent got programmed yet is that it will take the information they entered and then limit what division they are able to get into based on the number of doctrines in that division already. I am having a hard time figuring out how I am going to do that, will probably be a require_once to process the information after it has been sent to the table. I will then have to be able to query what members (by $name) are in there and send it to a seperate html window displayed on the front of our website.



Main Code

Code: Select all

<!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" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title>TLS Sign up Form</title>
</head>
<body>
<?php # TLS signup_form.php
<form name="TLSsignup" method="post" action="<?php echo $PHP_SELF; ?>">;
 
//Get the mysql connect script
require_once('mysqli_connect.php');
 
// Create a shorthand for the form data:
$name = $_POST['name'];
$faction = $_POST['faction'];
$allies_doctrines = $_POST['allies_doctrines'];
$axis_doctrines = $_POST['axis_doctrines'];
$allies_divisions = $_POST['allies_divisions'];
$axis_divisions = $_POST['axis_divisions'];
$time_zone = $_POST[time_zone'];
 
//Generate the arrays needed.
$allies_doctrines = array (1 => 'infantry','airborne','armor');
$axis_doctrines = array (1 => 'terror','blitzkrieg','defense');
$allies_divisions = array (1 => '1st_infantry','82nd_airborne','3rd_armored','101st_airborne','3rd_infantry','6th_armored');
$axis_divisions = array (1 => '84th_infanterie','16th_ss_panzer','21st_panzer','352nd_infanterie','2nd_panzer','1st_ss_panzer');
$time_zone = array (1 => 'north_america','europe');
$faction = (1 => 'allies','axis');
 
//Get profile name
$name = <input type = "text" size= "12" maxlength="16" name= "name"><br/>
 
//Select your faction, create the faction drop down menu.
echo ('Choose your Faction');
   echo '<select name = "faction">'
      foreach ($faction as $key => $value {
         echo ", option value =\$key\"> $value </option>\n";
}
   echo '</select>;
 
$faction = $value;
 
if ($faction($_POST[faction]=="allies")) {
echo ('Choose your doctrine');
   echo '<select name = "allies_doctrines">'
      foreach ($allies_doctrines as $key => $value {
         echo ", option value =\$key\"> $value </option>\n;
}
   echo '</select>';
$doctrine=$value ;
//choose your division for allies.  3 arrays for 3 different choices. Each choice kept as a seperate record for later use.
//first choice
    echo ('Choose your top 3 Division choices');
       echo '<select name = "allies_divisions">'
          foreach ($allies_divisions as $key => $value {
         echo ", option value =\$key\"> $value </option>\n;
}
   echo '</select>';
$choice1 = $value;
//second choice
       echo '<select name = "allies_divisions">'
          foreach ($allies_divisions as $key => $value {
         echo ", option value =\$key\"> $value </option>\n;
}
   echo '</select>';
$choice2 = $value;
//third choice
       echo '<select name = "allies_divisions">'
          foreach ($allies_divisions as $key => $value {
         echo ", option value =\$key\"> $value </option>\n;
}
   echo '</select>';
$choice3 = $value;
     
}else {
//choose your division for axis.  3 arrays for 3 different choices. Each choice kept as a seperate record for later use.
//first choice
    echo ('Choose your top 3 Division choices');
       echo '<select name = "axis_divisions">'
          foreach ($axis_divisions as $key => $value {
         echo ", option value =\$key\"> $value </option>\n;
}
   echo '</select>';
$choice1 = $value;
//second choice
       echo '<select name = "axis_divisions">'
          foreach ($axis_divisions as $key => $value {
         echo ", option value =\$key\"> $value </option>\n;
}
   echo '</select>';
$choice2 = $value;
//third choice
       echo '<select name = "axis_divisions">'
          foreach ($axis_divisions as $key => $value {
         echo ", option value =\$key\"> $value </option>\n;
}
   echo '</select>';
$choice3 = $value;
}
//Get the time zone
echo ('Please select your time zone.');
   echo '<select name ="time_zone">'
    foreach ($time_zone as $key => $value {
       echo ", option value =\$key\"> $value </option>\n;
}
    echo '</select>';
$time_zone=$value;
 
//Instert the data entered into the database.
$q = "INSERT INTO users (faction, time_zone, division, doctrine, name) VALUES ('$faction','$time_zone','$choice1','$choice2','$choice3','$doctrine','$name')";
$r = @mysqli_query($dbc, $q);
//check to make sure that the data was sent to the database.
if ($r) {
    echo '<h1> Thank You</h1>
        <p>You have been registered for The Last Stand</p><p><br />
        </p>
      }
else    {
    echo '<h1>Error</h1>
        <p class ="error"> There was an error in the system, we apologize; please go back and register again.</p>';
    echo '<p>'.mysqli_error($dbc).<br/>Query:'.$q.'</p>';
      }
 
?>
</body>
</html>
 
If you guys could help me with the code, look it over and see if I made any mistakes or where I can optimize it better, I would greatly appreciate it. I have to have this up and running by Saturday :(

Re: Sign-Up Form help/suggestion

Posted: Tue Jul 22, 2008 3:32 pm
by WebbieDave
Your table scheme leads me to believe that a user can belong to up to three divisions. Is that correct? If not, why are there three division fields?

If a user can only belong to one division, couldn't one deduce which faction a user belonged to from division.id alone? I guess I'm trying to see if there's room for normalization, which will make coding/querying much easier for you.

For instance:

Code: Select all

 
Table: Faction
id  name
1   CoolFaction
2   HotFaction
 
 
Table: Division
id  faction_id  name
1   1           DivA
2   1           DivB
3   2           DivA
4   2           DivB
 

Re: Sign-Up Form help/suggestion

Posted: Tue Jul 22, 2008 7:24 pm
by Draygon
Thanks for the response. I have it set that way (right now at least) because as you see in the code they choose 3 divisions that they can belong to.

I see what your saying and actually that should be just division (not 1-3) because I plan on calling a page to do some limiting to the factions. For instance if they choose 101st Airborne, 5th Armored and 1st Infantry as their divisions, there can only be 10 AB in the 101st, none in the 5th Armord and 1st Infantry. So I will try and put them in the top choice but if its full then it will go to choice 2 and check to see if they can get a spot in there. It is even further limited within the Armor and Infantry divisions, for instance there can only be 6 Armor players and 4 infantry players in a Armored division and 6 Infantry and 4 armored players in a infantry division.

Still trying to figure out how I am going to code that page. I suppose when I do figure that out I will call it, get the division that they will belong to and then plug that into the database.

How does the rest of the code look, besides that I missed the submit and the /form in at the bottom.