Sorry all for posting on here so soon again but im really having problems with my data getting entered into my database...
In the 1st query i want the query to select the users teamid when they are logged in so that the correct player goes into the correct team and the 2nd query just to input the data into the database.
<?php
require ("securelogin.php");
$username = $_SESSION['username'];
?>
<?php
//Insert managers into users table
//users Table
##### Table Structure #######
## playerid Firstname Surname Position Number ####
include "common.php";
//make connection to database
DBConnect();
$playerid = NULL;
$firstname = $_REQUEST['firstname'];
$surname = $_REQUEST['surname'];
$position = $_REQUEST['position'];
$number = $_REQUEST['number'];
$action = $_REQUEST['action'];
//If statement to check if the user has entered anything into the feilds.
if($action=="Register"){
if(!$firstname&&!$surname){
$message = "Both Form Fields Not Filled In!";
header("location: enterplayers.php?message=$message");
}elseif(!$firstname){
$message ="You did not fill in the first name form field";
header("location: enterplayers.php?message=$message");
}elseif(!$surname){
$message = "You did not fill in the surname form field";
header("location: enterplayers.php?message=$message");
}else{$Link = mysql_connect($Dhost, $Duser, $Dpassword);
//Prevent MySQL injection
$firstname = mysql_real_escape_string($firstname);
$surname = mysql_real_escape_string($surname);
$Query1 = "SELECT username, teamid FROM $tbl_user WHERE teamid = '$teamid'";
// Query is inserting data into the database using the Values from the from.
$Query2 = "INSERT into $tbl_player values ('$playerid', '$firstname', '$surname', '$position', '$number', '$teamid')";
$res1 = mysql_db_query ($DBName, $Query1, $Link);
if ($res1 === true && $res2 === true){
//Created successfully
$message = "Player was entered into your team please enter another";
}else{ // something went wrong in mysql_query()
$message = "Player could not be created! please try again";
echo 'DB Error: ' . mysql_error(); // get error info
mysql_close($Link);
exit(); // stop the script
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>FYP - Teesside Football United</title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
</head>
<body>
<div id="header"></div>
<div id="content">
<div id="right">
<div id="introwrap" class="clearfix">
<div class="introtext">
<h1>Enter Players</h1>
</div>
</div>
<p> </p>
<form id="form2" method="post" action="enterplayers.php?action=Register">
<p>
<label>First Name
<input type="text" name="firstname" id="firstname" />
</label>
</p>
<p>
<label>Surname
<input type="text" name="surname" id="surname" />
</label>
</p>
<p>
<label>Position
<select name="position" id="position">
<option selected="selected">GK</option>
<option>RB</option>
<option>LB</option>
<option>CB</option>
<option>RM</option>
<option>LM</option>
<option>CM</option>
<option>DCM</option>
<option>ACM</option>
<option>RF</option>
<option>LF</option>
<option>CF</option>
</select>
</label>
</p>
<p>
<label>Number
<select name="number" id="number">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
</select>
</label>
</p>
<p>
<label>
<input type="submit" name="Add Another Player" id="AddPlayer" value="Add Another Player" />
</label>
</p>
<p> </p>
</form>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</div>
<div id="left">
<h3>Manager Page</h3>
<ul>
<li><a href="index.php">Home Page</a></li>
<li><a href="teams.php">Teams</a></li>
<li><a href="comp.php">Competition</a></li>
<li><a href="contact.html">Contact Us</a></li>
<li><a href="adminlogin.php">Admin Page</a></li>
</ul>
<h3>Manager Tools</h3>
<ul>
<li><a href="index.html">Team</a></li>
<li><a href="mancomps.html">Competitions</a></li>
<li>
<form id="form1" method="post" action="logout.php">
<label>
<input type="submit" name="logout" id="logout" value="Logout" />
</label>
</form>
</li>
</ul>
</div>
</div>
</body>
</html>
Hope someone can help and thanks very much for looking