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:
users Table
players Table:
 players Table
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.

$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'";

$sqlb="SELECT p_ID, p_Name FROM players WHERE p_Class = 'B'";

$sqlc="SELECT p_ID, p_Name FROM players WHERE p_Class = 'C'";


while ($row=mysql_fetch_array($result1)) {
	$options1.="<OPTION VALUE=\"$id\">".$name.'</OPTION>';
while ($row=mysql_fetch_array($result2)) {
	$options2.="<OPTION VALUE=\"$id\">".$name.'</OPTION>';
while ($row=mysql_fetch_array($result3)) {
	$options3.="<OPTION VALUE=\"$id\">".$name.'</OPTION>';
 <form name="register" action="createNewTeam.php" method="post">
 <input type="hidden" name="redirect"value="register_success.html" />
    <th colspan="3" scope="col">Pick your team!</th>
    <td colspan="3" scope="col">Team Name: <input type="text" name="tName" /></td>
    <td>A Class<br />(choose 3)</td>
    <td>B Class<br />(choose 3)</td>
    <td>C Class<br />(choose 3)
		<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 />
		<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 />
		<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>Tie Breaker</td>
    <td><input type="text" name="breaker" size="10" /></td>
    <td colspan="3"><center><input type="reset" value="Clear" /> <input type="submit" value="Submit" /></center></td>


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
 teams Table
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.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Not sure what the exact question is here, but I can help with the part that is fairly clear: do not know how to create a session once credentials are passed.

I have an article here at EE that teaches the design patterns for registration and login.

To create a session, you use session_start() at the top of every page, unconditionally, no exceptions.

To add and remove information from the session, you put elements into the superglobal variable $_SESSION.   Example:
$_SESSION["count"] = 0; // MAKES count = ZERO
$_SESSION["count"]++;  // MAKES count = ONE

If you follow those guidelines, you will have persistent session data across web pages.  Each script will find what the previous script put into the $_SESSION array.

Sessions expire (usually) when the browser is closed or after 24 minutes of inactivity.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NCollinsBBPAuthor Commented:
Thank you.
This provided the guidance required for complete my task.

Ray PaseurCommented:
Thanks for the points - it's a great question, ~Ray
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.