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.

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

-Nick
NCollinsBBPAsked:
Who is Participating?

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

x
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.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391-PHP-login-logout-and-easy-access-control.html

To create a session, you use session_start() at the top of every page, unconditionally, no exceptions.
http://php.net/manual/en/function.session-start.php

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
unset($_SESSION["count"]); // ELIMINATES THE count FROM THE SESSION

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.

-Nick
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
PHP

From novice to tech pro — start learning today.