I have this problem here where when I press the Add button, it should save my selected choices into my table in database.
But when I press it, my table in database did not receive any data.
Did I do something wrong with my code? I need to find a right way to save the data into my designated table.
Any help would be greatly appreciated. Thanks
<?php
include "..\subjects\connect3.php";
//echo "Connection successs";
$query = "SELECT * FROM programmes_list";
$result = mysqli_query($link, $query);
?>
<form name = "form1" action="dropdownindex.php" method="post">
<table>
<tr>
<td>Select Pragramme</td>
<td>
<select id="programmedd" onChange="change_programme()">
<option>select</option>
<?php while($row=mysqli_fetch_array($result)) { ?>
<option value="<?php echo $row["ID"]; ?>"><?php echo $row["programme_name"]; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td>Select intake</td>
<td>
<div id="intake">
<select>
<option>Select</option>
</select>
</div>
</td>
</tr>
<tr>
<td>Select Subjects</td>
<td>
<div id="subject">
<select >
<option>Select</option>
</select>
</div>
</td>
</tr>
<input type="submit" value="Add" name="send">
</table>
</form>
<?php
if(isset($_POST['Add'])) {
//print_r($_POST);
$course1 = implode(',',$_POST['programmedd']);
$course2 = implode(',',$_POST['intake']);
$course3 = implode(',',$_POST['subject']);
$db->query("INSERT INTO programmes(programme_registered, intake_registered, subjects_registered)
VALUES (' ".$course1." ',' ".$course2." ', ' ".$course3." ' )");
echo $db->affected_rows;
}
?>
<script type="text/javascript">
function change_programme()
{
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","ajax.php?programme="+document.getElementById("programmedd").value,false);
xmlhttp.send(null);
document.getElementById("intake").innerHTML=xmlhttp.responseText;
if(document.getElementById("programmedd").value=="Select"){
document.getElementById("subject").innerHTML="<select><option>Select</option></select>";
}
}
function change_intake()
{
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","ajax.php?intake="+document.getElementById("intakedd").value,false);
xmlhttp.send(null);
document.getElementById("subject").innerHTML=xmlhttp.responseText;
}
</script>
//ajax.php
<?php
$dbhost = 'localhost' ;
$username = 'root' ;
$password = '' ;
$db = 'programmes' ;
$link = mysqli_connect("$dbhost", "$username", "$password");
mysqli_select_db($link, $db);
if (isset($_GET["programme"])) {
$programme = $_GET["programme"];
} else {
$programme = "";
}
if (isset($_GET["intake"])) {
$intake = $_GET["intake"];
} else {
$intake = "";
}
if ($programme!="") {
$res=mysqli_query($link, "select * from intakes where intake_no = $programme");
echo "<select id='intakedd' onChange='change_intake()'>";
echo "<option>" ; echo "Select" ; echo "</option>";
while($value = mysqli_fetch_assoc($res)) {
echo "<option value=".$value['ID'].">";
echo $value["intake_list"];
echo "</option>";
}
echo "</select>";
}
if ($intake!="") {
$res=mysqli_query($link, "select * from subject_list where subject_no = $intake");
echo "<select>";
echo "<option>" ; echo "Select" ; echo "</option>";
while($value = mysqli_fetch_assoc($res)) {
echo "<option value=".$value['ID'].">";
echo $value["subjects"];
echo "</option>";
}
echo "</select>";
}
?>
Your error is where you check for button click.
Change to this
If(isset($_POST['send']))
For future purposes and references, When doing the above, include the name attribute from your button and not the value attribute
Related
I stored values from a form in SESSION variables but it seems that they are emptied after if(isset($_POST['submit']) even though I can echo them earlier in my code. The code runs and the insert works except for $toto and $tata which are empty.
In the code below _id, master_label, client_label are inserted correctly. And the target table fields match so the error does not come from there.
<?php
session_start();
[...]
echo "<form id='organization' action='?' method='POST' enctype='multipart/form-data' >" ;
echo "<select name='organization' onchange='this.form.submit()'>"; //
echo '<option value="">Select ORGANIZATION</option>';
while ($row=mysqli_fetch_array($result00)) {
echo '<option value="'.$row['company_id'].'">'.$row['company_id'].'</option>';
}
echo "</select>";
echo "</form>";
$cie_ticker = $_POST['organization'] ;
$_SESSION['company_id'] = $cie_ticker ;
$sql="(SELECT company_id, databasefile, company_name FROM `settings` WHERE company_id='$cie_ticker') LIMIT 1";
$result=mysqli_query($connect,$sql) or die('Could not execute the query ' . mysqli_error()) ;
$data_bis=$result->fetch_array() ;
$_SESSION['selected_cie_id'] = $data_bis['company_id'];
$_SESSION['selected_cie_name'] = $data_bis['company_name'];
<form id='demoForm' action="?" method="POST" enctype="multipart/form-data" target="_top">
<?php
$file = fopen('./company/'.$cie_ticker.'/'.$_SESSION['selected_cie_db'], "r") ; // $file = fopen('./company/'.$_SESSION["company_id"].'/'.$_SESSION['selected_cie_db'], "r") ;
$headers=fgetcsv($file, 1000, "|");
fclose($file);
?>
<table id="user_table">
<tr><th>HEADERS </th><th>MASTER DB HEADERS</th></tr>
<?php foreach ($headers as $entete) {
$query01="SELECT master_label FROM `mastertable`";
$result01=mysqli_query($connect,$query01); ?>
<tr id="<?php echo $entete;?>">
<td> <?php echo $entete ?></td>
<td id="<?php echo $row['_id'];?>">
<?php
echo "<br>";
echo "<select name=".$entete.">";
echo '<option value="MASTER DATA">Select MASTER DATA</option>';
while ($row=mysqli_fetch_array($result01)) {
echo '<option value="'.$row['master_label'].'">'.$row['master_label'].'</option>';
}
echo "</select>";
?>
</td>
</tr>
<?php } ?>
</table>
<input id="checkBtn" type="submit" name="submitbutton" value="SAVE" class="button"/>
</form>
if(isset($_POST['submitbutton'])) {
$toto = $data_bis['company_id'] ;
$tata = $data_bis['company_name'];
$selected=$_POST;
foreach($selected as $x => $x_value) {
$query= $connect->prepare("INSERT INTO `mytable` (_id, master_label, client_label, org_label, client_id) VALUES ('',?,?,?,?) ");
$query->bind_param('ssss',$x_value, $x, $toto, $tata );
$query->execute();
}
}
?>
I have found the answer:
In this case one must add hidden input for the $_SESSION variables otherwise they were lost after submitting the form.
I am developing a simple attendance system in which the attendance is taken by the a teacher and then saved to the database. However, I am having a problem with saving the data to the database. when i click on "submit attendance" the data won't be submitted to the database. i use register.php to register students but take the attendance in different file.
Below is the code i use to submit. Can someone help me? Thanks.
sorry the file i shared was supposed to save data to mysql database. Below is the file which takes the data and am still having the problem for saving it.
this is the teacher file to take the attendance
teacher.php
<?php
$pageTitle = 'Take Attendance';
include('header.php');
require("db-connect.php");
if(!(isset($_COOKIE['teacher']) && $_COOKIE['teacher']==1)){
echo 'Only teachers can create new teachers and students.';
$conn->close();
include('footer.php');
exit;
}
//get session count
$query = "SELECT * FROM attendance";
$result = $conn->query($query);
$sessionCount=0;
setcookie('sessionCount', ++$sessionCount);
if(mysqli_num_rows($result)>0){
while($row = $result->fetch_assoc()){
$sessionCount = $row['session'];
setcookie('sessionCount', ++$sessionCount);
}
}
if(isset($_GET['class']) && !empty($_GET['class'])){
$whichClass = $_GET['class'];
$whichClassSQL = "AND class='" . $_GET['class'] . "'";
} else {
$whichClass = '';
$whichClassSQL = 'ORDER BY class';
}
echo '
<div class="row">
<div class="col-md-4">
<div class="input-group">
<input type="number" id="session" name="sessionVal" class="form-control" placeholder="Session Value i.e 1" required>
<span class="input-group-btn">
<input id="submitAttendance" type="button" class="btn btn-success" value="Submit Attendance" name="submitAttendance">
</span>
</div>
</div>
<div class="col-md-8">
<form method="get" action="' . $_SERVER['PHP_SELF'] . '" class="col-md-4">
<select name="class" id="class" class="form-control" onchange="if (this.value) window.location.href=this.value">
';
// Generate list of classes.
$query = "SELECT DISTINCT class FROM user ORDER BY class;";
$classes = $classes = mysqli_query($conn, $query);
if($classes && mysqli_num_rows($classes)){
// Get list of available classes.
echo ' <option value="">Filter: Select a class</option>';
echo ' <option value="?class=">All classes</option>';
while($class = $classes->fetch_assoc()){
echo ' <option value="?class=' . $class['class'] . '">' . $class['class'] . '</option>';
}
} else {
echo ' <option value="?class=" disabled>No classes defined.</option>';
}
echo '
</select>
</form>
</div>
</div>
';
$query = "SELECT * FROM user WHERE role='student' $whichClassSQL;";
$result = $conn->query($query);
?>
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Class</th>
<th>Present</th>
<th>Absent</th>
</tr>
</thead>
<tbody>
<form method="post" action="save-attendance.php" id="attendanceForm">
<?php
if(mysqli_num_rows($result) > 0){
$i=0;
while($row = $result->fetch_assoc()){
?>
<tr>
<td><input type="hidden" value="<?php echo($row['id']);?>" form="attendanceForm"><input type="text" readonly="readonly" name="name[<?php echo $i; ?>]" value="<?php echo $row['fullname'];?>" form="attendanceForm"></td>
<td><input type="text" readonly="readonly" name="email[<?php echo $i; ?>]" value="<?php echo $row['email'];?>" form="attendanceForm"></td>
<td><input type="text" readonly="readonly" name="class[<?php echo $i; ?>]" value="<?php echo $row['class'];?>" form="attendanceForm"></td>
<td><input type="radio" value="present" name="present[<?php echo $i; ?>]" checked form="attendanceForm"></td>
<td><input type="radio" value="absent" name="present[<?php echo $i; ?>]" form="attendanceForm"></td>
</tr>
<?php $i++;
}
}
?>
</form>
</tbody>
</table>
<script>
$("#submitAttendance").click(function(){
if($("#session").val().length==0){
alert("session is required");
} else {
$.cookie("sessionVal", $("#session").val());
var data = $('form#attendanceForm').serialize();
$.ajax({
url: 'save-attendance.php',
method: 'post',
data: {formData: data},
success: function (data) {
console.log(data);
if (data != null && data.success) {
alert('Success');
} else {
alert(data.status);
}
},
error: function () {
alert('Error');
}
});
}
});
</script>
<?php
$conn->close();
include('footer.php');
save-attendance.
<?php
//include ("nav.php");
require("db-connect.php");
$query = "SELECT * FROM user WHERE role='student'";
$result = $conn->query($query);
$nameArray = Array();
$count = mysqli_num_rows($result);
if(isset($_COOKIE['sessionCount'])){
$sessionCount = $_COOKIE['sessionCount'];
}
//save record to db
if(isset($_POST['formData'])) {
//increment the session count
if(isset($_COOKIE['sessionCount'])){
$sessionCount = $_COOKIE['sessionCount'];
setcookie('sessionCount', ++$sessionCount);
}
parse_str($_POST['formData'], $searcharray);
//print_r($searcharray);die;
//print_r($_POST);
for ($i = 0 ; $i < sizeof($searcharray) ; $i++){
// setcookie("checkloop", $i);;
$name = $searcharray['name'][$i];
$email= $searcharray['email'][$i];
$class = $searcharray['class'][$i];
$present= $searcharray['present'][$i];
if(isset($_COOKIE['sessionVal'])){
$sessionVal = $_COOKIE['sessionVal'];
}
//get class id
$class_query = "SELECT * FROM class WHERE name='".$class."'";
$class_id = mysqli_query($conn, $class_query);
if($class_id){
echo "I am here";
while($class_id1 = $class_id->fetch_assoc()){
$class_id_fin = $class_id1['id'];
echo $class_id['id'];
}
}
else{
echo "Error: " . $class_query . "<br>" . mysqli_error($conn);
}
//get student id
$student_query = "SELECT * FROM user WHERE email='".$email."'";
$student_id = $conn->query($student_query);
if($student_id) {
while ($student_id1 = $student_id->fetch_assoc()) {
$student_id_fin = $student_id1['id'];
}
}
//insert or update the record
$query = "INSERT INTO attendance VALUES ( '".$class_id_fin."', '".$student_id_fin."' , '".$present."','".$sessionVal."','comment')
ON DUPLICATE KEY UPDATE isPresent='".$present."'";
print_r($query);
if(mysqli_query($conn, $query)){
echo json_encode(array('status' => 'success', 'message' => 'Attendance added!'));
} else{
echo json_encode(array('status' => 'error', 'message' => 'Error: ' . $query . '<br>' . mysqli_error($conn)));
}
}
$conn->close();
}
You did not provide a lot of information, but I understand from the comments that the error is $sessionVal is undefined.
if $_COOKIE['sessionVal'] is not set, try:
1- print_r($_COOKIE) and check if [sessionVal] is set;
2- Try to add a fallback to:
if(isset($_COOKIE['sessionVal'])){
$sessionVal = $_COOKIE['sessionVal'];
}
else {
$sessionVal = 0;
}
or
$sessionVal = (isset($_COOKIE['sessionVal'])) ? $_COOKIE['sessionVal'] : 0;
Bottom line, there is not point to check if a variable is set and not having a fallback in case it is not set.
I have a dropdown list with 2 option (LOCAL and IMPORT). The option for Import is working and I can get the value and echo the $refnumb (IMCK2016-0000001). But when I select LOCAL I get the same value of $refnumb IMCK2016-0000001 instead of LOCCK2016-0000001. Please help me find what's wrong with my code. Thanks.
<table id='tblselect' class=normal2 style='font-size:0.6em;'>
<tr><th align='right'>Shipment Type: </th>
<!--<tr><td><input type='submit' name='lookup_master' value='COPY' /></td></tr>-->
<?php $shipmenttype = array("0"=>"Please select...", "LOC"=>"LOCAL", "IM"=>"IMPORT");?>
<td><b><select name='shiptype' id='shiptype'>
<?php foreach($shipmenttype as $keyname=>$ship_type):?>
<?php
$selected ="";
$shiptype = $_POST['shiptype'];
if($keyname == $shiptype): $selected =" selected"; endif;
?>
<option value="<?php echo $keyname;?>" <?php echo $selected;?>><?php echo $ship_type;?></option>
<?php endforeach;?>
</select></b></td></tr>
</table>
<br><br>
<?php
$site = dbGetConfig("sitecode");
$dbnextID = dbNextID($keyname);
if($site=="CKI") {
$site="CK".date("Y");
}
if($site=="PQI") {
$site="PQ".date("Y");
}
$refnumb = $keyname.$site."-".str_pad($dbnextID,7,0, STR_PAD_LEFT);
?>
Reference Number:
<input type='text' name='ref_no1' id='ref_no1' value="<?php echo $refnumb ?>" readonly />
Here's the function for dbNextID.
function dbNextID($key) {
$sql1 = "insert into key_master (keyname) values (:keyname)";
$sql2= "update key_master set id = id + 1 where keyname = :keyname";
$sql3 = "select id from key_master where keyname = :keyname";
$conn = dbConnect();
$stmt1 = $conn->prepare($sql1);
$stmt2 = $conn->prepare($sql2);
$stmt3 = $conn->prepare($sql3);
$conn->beginTransaction();
$stmt1->execute(array(':keyname' => $key));
$stmt2->execute(array(':keyname' => $key));
$stmt3->execute(array(':keyname' => $key));
$value = $stmt3->fetchColumn(0);
$conn->commit();
$conn=null;
return $value;
}
Your variable $keyname is getting set inside your for loop. When you are printing out $refnumb, you are referencing $keyname outside the loop. This means that you will get the last element in $shipmenttype is "IM").
To fix this, you will need to track the selected value.
<table id='tblselect' class=normal2 style='font-size:0.6em;'>
<tr><th align='right'>Shipment Type: </th>
<!--<tr><td><input type='submit' name='lookup_master' value='COPY' /></td></tr>-->
<?php $selectedValue = 0; $shipmenttype = array("0"=>"Please select...", "LOC"=>"LOCAL", "IM"=>"IMPORT");?>
<td><b><select name='shiptype' id='shiptype'>
<?php foreach($shipmenttype as $keyname=>$ship_type):?>
<?php
$selected ="";
$shiptype = $_POST['shiptype'];
if($keyname == $shiptype) $selected =" selected";$selectedValue = $keyname; endif;
?>
<option value="<?php echo $keyname;?>" <?php echo $selected;?>><?php echo $ship_type;?></option>
<?php endforeach;?>
</select></b></td></tr>
</table>
<br><br>
<?php
$site = dbGetConfig("sitecode");
$dbnextID = dbNextID($selectedValue);
if($site=="CKI") {
$site="CK".date("Y");
}
if($site=="PQI") {
$site="PQ".date("Y");
}
$refnumb = $selectedValue.$site."-".str_pad($dbnextID,7,0, STR_PAD_LEFT);
?>
I need a help exporting search query by clicking on export button. I am able to get data from database to the browser. However, when I click on export button, it refreshes the page, and doesnt do anything.
I am new to php and and programming. Any help will be appreciated :)
<?php
include('dbcon.php');
?>
<form id="searchform" action="index.php" method="post">
<table>
<tr>
<td class="searchleftcol"><h3>Service:</h3></td>
<td>
<select id="service" name="service" class="searchoption">
<option value="">-- Select Service Name --</option>
<?php
$resultservice = mysqli_query($con,"Select * from services") ?>
<?php
while ($line = mysqli_fetch_array($resultservice)) {
?>
<option value="<?php echo $line['serviceid'];?>"> <?php echo $line['service'];?> </option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>
<h3>Environment:</h3>
</td>
<td>
<select id="environment" name="environment" class="searchoption">
<option value="">-- Select Environment --</option>
<?php
$resultdomain = mysqli_query($con,"Select * from evn") ?>
<?php
while ($line = mysqli_fetch_array($resultdomain)) {
?>
<option value="<?php echo $line['envid'];?>"> <?php echo $line['env'];?> </option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>
<h3>Status:</h3>
</td>
<td>
<select name="status" class="searchoption">
<option value="Active">Active</option>
<option value="Inactive">Inactive</option>
</select>
</td>
</tr>
</table>
<input type="reset" name="reset">
<input type="submit" name="submit" value="Search">
<input type="submit" name="export" value="Export" />
</ul>
</form>
<?php
if (isset($_POST['submit'])) {
if (empty($_POST['service'])) {
echo "Please select service in dropdown" . "</br>";
}
else {
$service = $_POST['service'];
}
if (empty($_POST['environment'])) {
echo "Please select Environment in dropdown" . "</br>";
}
else {
$env = $_POST['environment'];
}
if ((!empty($service)) && (!empty($env))) {
$sql="SELECT * from servers";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
$mydata = mysqli_query($con,$sql);
$rowcount = mysqli_num_rows($mydata);
// Here I erased code that displays data from MySQL.
if (isset($_POST['export'])) {
if (empty($_POST['service'])) {
echo "Please select service in dropdown" . "</br>";
}
else {
$service = $_POST['service'];
}
if (empty($_POST['environment'])) {
echo "Please select Environment in dropdown" . "</br>";
}
else {
$env = $_POST['environment'];
}
if ((!empty($service)) && (!empty($env))) {
$sql="SELECT * from servers";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
$mydata = mysqli_query($con,$sql);
$rowcount = mysqli_num_rows($mydata);
//Programetically get the Headings of the excel columns
$columns_total = mysqli_num_fields($sql);
for ($i = 0; $i < $columns_total; $i++) {
$heading = mysql_field_name($sql, $i);
$contents .= '"'.$heading.'",';
}
$contents .="\n";
// Get Records from the table
while ($row = mysqli_fetch_array($sql)) {
for ($i = 0; $i < $columns_total; $i++) {
$contents.='"'.$row["$i"].'",';
}
$contents.="\n";
}
// Remove html and php tags etc.
$contents = strip_tags($contents);
//header to make force download the file
Header("Content-Disposition: attachment; filename=ProductsReport".date('d-m-Y').".csv");
print $contents;
}
}
mysqli_close($con);
}
?>}
Thanks,
Ray
I have two tables, tblPlayer(PlayerID, PlayerName,PlayerTeam(int) ) and tblTeams (TeamID, TeamName)
On a PHP page I have a function to find the selected player, function is as follows,
function find_selected_player() {
global $sel_player;
if (isset($_GET['id'])) {
$sel_player = get_player_by_id($_GET['id']);
} else {
$sel_player = NULL;
}
}
my other function as follows,
function get_player_by_id($player_id) {
global $conn;
$query = "SELECT * ";
$query .= "FROM tblPlayer ";
$query .= "WHERE PlayerID =" . $player_id ." ";
$query .= "LIMIT 1";
$result_set = mysql_query($query, $conn);
confirm_query($result_set);
if ($player = mysql_fetch_array($result_set)) {
return $player;
} else {
return NULL;
}
}
So on the form to edit I can get all values like
<input type="text" name="PlayerName" value="<?php echo $sel_player['PlayerName']; ?>" />
But...:) when I try to fill up a combo box with the reverse way I am stuck there. When adding something this works like a charm but $sel_player['PlayerTeam'] is giving me only ID :(
<?php include "conn.php" ?>
<?php include "function.php" ?>
<?php find_selected_player() ?>
<h2>Edit: <?php echo $sel_player['PlayerName'] ." ". $sel_player['PlayerLname']; ?></h2>
<form action="player.php" method="post">
<table>
<tr>
<td>Name: </td>
<td><input type="text" name="PlayerName" value="<?php echo $sel_player['PlayerName']; ?>" /></td>
</tr>
<tr>
<td>Lastname:</td>
<td><input type="text" name="PlayerLname" value="<?php echo $sel_player['PlayerLname']; ?>" /></td>
</tr>
<tr>
<td>Team:</td>
<td>
<?php
$sql = "SELECT TeamName, TeamID FROM tblTeam";
$result = mysql_query($sql);
echo '<select name="TeamName"><option>';
echo "Choose a team.</option>";
echo '<option selected>' . $sel_player['PlayerTeam'] . '</option>';
while ($row = mysql_fetch_array($result)) {
$team_name= $row["TeamName"];
$team_id = $row["TeamID"];
echo "<option value=\"$team_id\">$team_name</option>";
}
echo "</select>";
?>
</td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Save" /></td>
<td align="right"> </td>
</tr>
</table>
</form>
<?php ob_end_flush() ?>
<?php include ("footer.php") ?>
You should update your code to use MySQLi_*, or PDO. I've gotten you started here. Try this out and see how it works for you.
function getPlayerByID($pid = '')
{
global $conn;
if($pid == '')
return false;
$sql = mysql_query("SELECT * FROM tblPlayer WHERE PlayerID = '$pid'", $conn);
$row = mysql_fetch_array($sql);
if(mysql_num_rows($sql) == 1)
return $row;
else
return false;
}
$id = isset($_GET['id']) ? $_GET['id'] : '';
$sel_player = getPlayerByID($id);
$sql = mysql_query("SELECT TeamName, TeamID FROM tblTeam");
$select = '<select name=""><option>Choose a Team</option>';
while($row = mysql_fetch_array($sql))
{
$team_id = $row['TeamID'];
$team_name = $row['TeamName'];
$selected = $team_id == $sel_player['PlayerTeam'] ? 'selected' : '';
$select .= '<option ' . $selected . ' value="' . $team_id . '">' . $team_name . '</option>';
}
$select .= '</select>';
echo $select;
$team_adi should be $team_name
Change:
echo "<option value=\"$team_id\">$team_adi</option>";
to:
echo "<option value=\"$team_id\">$team_name</option>";
<?php
$sql = "SELECT TeamName, TeamID FROM tblTeam";
$result = mysql_query($sql);
$player_id = $_GET['id'];
$current_team = mysql_query("SELECT
tblteam.TeamID,
tblteam.TeamName,
tblplayer.PlayerID,
tblplayer.PlayerTeam,
tblplayer.PlayerName
FROM
tblplayer
INNER JOIN tblteam ON tblplayer.PlayerTeam = tblteam.TeamID
WHERE PlayerID = $player_id LIMIT 1 ");
$my_row = mysql_fetch_array($current_team);
?>
<select name="TeamName">
<option selected value="<?php echo $my_row['TeamID']; ?>"> <?php echo $my_row['TeamName']; ?> </option>
<?php
while ($row = mysql_fetch_array($result)) {
$team_name= $row["TeamName"];
$team_id = $row["TeamID"];
echo "<option value=\"$team_id\">$team_name</option>";
}
echo "</select>";
?>