Link to home
Create AccountLog in
Avatar of NCollinsBBP
NCollinsBBPFlag for United States of America

asked on

Create MySQL Data from HTML / PHP Forms with Login

Experts-Exchange Team,

I'm creating a page to generate a login / registration site where you can create a team of players in a sporting event based on their player class.   My database looks like this so far...

users Table:
User generated image
players Table:
 User generated image
I have the registration system up and running for users to create their account.

I can easily create the login form, but do not know how to create a session once credentials are passed.

I want to use the "user_email" in the users table as the login name (password is obvious).  And from their login session, have the option to create their team.  

The team is to consist of 3 players from the A Class, 3 from B Class and 3 from C Class (from the "p_Class" field in the 'players' table.  

The form I have so far is as follows.

newteam.php
<?php
$con = mysql_connect("localhost", "bbpextr1_orion", "Ianr0ck5!");
if (!$con) {
    die('Could not connect: ' . mysql_error());
}

mysql_select_db("bbpextr1_masters2011", $con);

$sqla="SELECT p_ID, p_Name FROM players WHERE p_Class = 'A'";
$result1=mysql_query($sqla);

$sqlb="SELECT p_ID, p_Name FROM players WHERE p_Class = 'B'";
$result2=mysql_query($sqlb);

$sqlc="SELECT p_ID, p_Name FROM players WHERE p_Class = 'C'";
$result3=mysql_query($sqlc);

$options1="";
$options2="";
$options3="";

while ($row=mysql_fetch_array($result1)) {
	
	$id=$row["p_ID"];
	$name=$row["p_Name"];
	$options1.="<OPTION VALUE=\"$id\">".$name.'</OPTION>';
}
while ($row=mysql_fetch_array($result2)) {
	
	$id=$row["p_ID"];
	$name=$row["p_Name"];
	$options2.="<OPTION VALUE=\"$id\">".$name.'</OPTION>';
}
while ($row=mysql_fetch_array($result3)) {
	
	$id=$row["p_ID"];
	$name=$row["p_Name"];
	$options3.="<OPTION VALUE=\"$id\">".$name.'</OPTION>';
}
?>
 <form name="register" action="createNewTeam.php" method="post">
 <input type="hidden" name="redirect"value="register_success.html" />
 
 <table>
  <tr>
    <th colspan="3" scope="col">Pick your team!</th>
    </tr>
  <tr>
    <td colspan="3" scope="col">Team Name: <input type="text" name="tName" /></td>
  </tr>
  <tr>
    <td>A Class<br />(choose 3)</td>
    <td>B Class<br />(choose 3)</td>
    <td>C Class<br />(choose 3)
         
    </td>
  </tr>
  <tr>
    <td>
		<SELECT NAME=<? $name ?>><OPTION VALUE=0 name='a1'>Choose...<?=$options1?></OPTION></SELECT><br /><br />
        <SELECT NAME=<? $name ?>><OPTION VALUE=0 name='a2'>Choose...<?=$options1?></OPTION></SELECT><br /><br />
        <SELECT NAME=<? $name ?>><OPTION VALUE=0 name='a3'>Choose...<?=$options1?></OPTION></SELECT><br /><br /><br /><br /><br />
    </td>
    <td>
		<SELECT NAME=<? $name ?>><OPTION VALUE=0 name='b1'>Choose...<?=$options2?></OPTION></SELECT><br /><br />
        <SELECT NAME=<? $name ?>><OPTION VALUE=0 name='b2'>Choose...<?=$options2?></OPTION></SELECT><br /><br />
        <SELECT NAME=<? $name ?>><OPTION VALUE=0 name='b3'>Choose...<?=$options2?></OPTION></SELECT>    <br /><br /><br /><br /><br />
    </td>
    <td>
		<SELECT NAME=<? $name ?>><OPTION VALUE=0 name='c1'>Choose...<?=$options2?></OPTION></SELECT><br /><br />
        <SELECT NAME=<? $name ?>><OPTION VALUE=0 name='c2'>Choose...<?=$options2?></OPTION></SELECT><br /><br />
        <SELECT NAME=<? $name ?>><OPTION VALUE=0 name='c3'>Choose...<?=$options2?></OPTION></SELECT
    </td>
  </tr>
  <tr>
    <td>Tie Breaker</td>
    <td><input type="text" name="breaker" size="10" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3"><center><input type="reset" value="Clear" /> <input type="submit" value="Submit" /></center></td>
    </tr>
 </table>

</form>

Open in new window


I want to be able to pass the data from this form into a table named "teams" from a file named creatNewTeam.php when SUBMIT is pressed.

team Table
 User generated image
t_ID = Auto Increment INT
t_owner should be the "userID" from the current session taken from the "users" table.
t_Name from the "tName" input field in the form.
t_breaker from the "breaker" field in the form.
t_a01, etc etc... to be from the "p_ID" in the "players" table taken from their drop down selection.

I hope this is enough detail on what I'm looking for.  Any assistance will be greatly appreciated.

-Nick
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of NCollinsBBP

ASKER

Thank you.
This provided the guidance required for complete my task.

-Nick
Thanks for the points - it's a great question, ~Ray