0

I have been struggling with these two pages for awhile. I have one page with a form which shows different data depending on who is logged in. There is one drop down adjustment field that the users between "Active" and "Bench". The submitted form should be updating that field in the database. The form shows fine and posts to the update page but nothing changes in the database. I'm not sure if the problem is with the variables, the array from the select input or the update query.

Any help would be much appreciated.

<?php
session_start();

require('/conn_ssfhl.php'); 

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_DetailRS1 = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_DetailRS1 = $_SESSION['MM_Username'];
}
mysql_select_db($database_conn_ssfhl, $conn_ssfhl);
$query_DetailRS1 = sprintf("SELECT PlayerID, FanID, Type, InjuryID, Player, StatusID, StatusChangeChoice, CurrentWeek, GMEmail FROM tblplayers WHERE GMEmail = %s ORDER BY tblplayers.Type Asc", GetSQLValueString($colname_DetailRS1, "text"));
$DetailRS1 = mysql_query($query_DetailRS1, $conn_ssfhl) or die(mysql_error());
$row_DetailRS1 = mysql_fetch_assoc($DetailRS1);
$totalRows_DetailRS1 = mysql_num_rows($DetailRS1);


$colname_rsGMDetail = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_rsGMDetail = $_SESSION['MM_Username'];
}
mysql_select_db($database_conn_ssfhl, $conn_ssfhl);
$query_rsGMDetail = sprintf("SELECT GMFirst, GMLast FROM tbluseradmin WHERE GMEmail = %s", GetSQLValueString($colname_rsGMDetail, "text"));
$rsGMDetail = mysql_query($query_rsGMDetail, $conn_ssfhl) or die(mysql_error());
$row_rsGMDetail = mysql_fetch_assoc($rsGMDetail);
$totalRows_rsGMDetail = mysql_num_rows($rsGMDetail);

// Count rows in table
$count=mysql_num_rows($DetailRS1);

// Post variables
$player = $_POST['hideplayerID'];
$playerid = $_POST['PlayerID'];


if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>form</title>
</head>
<body bgcolor="#FFFFFF">
<form id="frmupdate" name="frmupdate" method="post" action="update2.php">
  <table width="500" border="0" cellspacing="1" cellpadding="0">
    <tr>
      <td align="center" bgcolor="#FFCC00"><strong>ID</strong></td>
      <td align="center" bgcolor="#FFCC00">Position</td>
      <td align="center" bgcolor="#FFCC00">Player</td>
      <td align="center" bgcolor="#FFCC00">Health</td>
      <td align="center" bgcolor="#FFCC00">Current Status</td>
      <td align="center" bgcolor="#FFCC00"><strong>Change Status</strong></td>
    </tr>
    <?php
// Fetch record rows in $DetailRS1 by while loop and put them into $row.
while($row=mysql_fetch_assoc($DetailRS1)){
?>
    <tr>
      <td bgcolor="#FFFFCC"><? echo $row['PlayerID']; ?>
        <input name="hideplayerID" type="hidden" id="hideplayerID" value="<?php echo $row_DetailRS1['PlayerID']; ?>" /></td>
      <td bgcolor="#FFFFCC"><? echo $row['Type']; ?></td>
      <td bgcolor="#FFFFCC"><? echo $row['Player']; ?></td>
      <td bgcolor="#FFFFCC"><? echo $row['InjuryID']; ?></td>
      <td bgcolor="#FFFFCC"><? echo $row['StatusID']; ?></td>
      <td bgcolor="#FFFFCC"><label>
        <select name="select[]">
          <option value="Active" selected="selected">Active</option>
          <option value="Bench">Bench</option>
        </select>
      </label></td>
    </tr>
    <tr> </tr>
    <?php } // End while loop. ?>
  </table>
   <p>
                  <input type="submit" name="submit" value="submit" />
</p>
</form>
</body>
</html>

Page 2
<?php require_once('../conn_ssfhl.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>update</title>
</head>
<body>
<?php
// If receive Submit button variable.
if($_POST['submit']){ 

// Select all data records in table "tblplayers" and put them into $result.
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
 # Script 2.5 - update.php

//Validate the status and combat Magic Quotes, if neccessary.
if (!empty($_REQUEST['select'])) {
$select = stripslashes($_REQUEST['select']);
} else {
$select = NULL;
echo '<p>You forgot to change your player status!</p>';
}

//If everything else is okay, print the message
echo "<p>Thank you</p>";

} 
else {//Selection was not made on form.
echo "<p>Please go back and complete your selections.</p>";
}

mysql_select_db($database_conn_ssfhl, $conn_ssfhl);
$query_result = "SELECT PlayerID FROM tblplayers ORDER BY PlayerID ASC";
$result = mysql_query($query_result, $conn_ssfhl) or die(mysql_error());
$row_result = mysql_fetch_assoc($result);
$totalRows_result = mysql_num_rows($result);

// Fetch record rows in $result by while loop and put them into $row.
while($row = mysql_fetch_assoc($result)){
if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so am exiting";
    exit;
}
while ($row = mysql_fetch_assoc($result)) {
    echo $row["PlayerID"];
}
//start a counter in order to number the input fields for each record
for($i=0;$i<$count;$i++){

// Update field "StatusChangeChoice", matching with "PlayerID" value by while loop.
$query_update = "UPDATE tblplayers SET StatusChangeChoice = '$selectChoice' where PlayerID = '$player'";
              }
   }
$update = mysql_query($query_update, $conn_ssfhl) or die(mysql_error());
if (!$update) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query_update;
    die($message);
}
//}
echo "--- Update Complete ---";

echo  "This is the query : ". $query_update;
?>
</body>
</html>
<?php
mysql_free_result($result);

?>
2
Contributors
19
Replies
23
Views
7 Years
Discussion Span
Last Post by Mrgrinch12
0

For one thing you have two

while ($row = mysql_fetch_assoc($result))

loops. When the first ends, the pointer is at the end of the result set, thus the second loop never gets executed. To do it that way you would have to reset the pointer with mysql_data_seek($result,0) before the second loop. But all you're doing in the second loop is echo-ing the playerid (for debugging?) so that's not really your problem.

But

for($i=0;$i<$count;$i++){

- I don't think $count is ever set? Thus that loop never gets executed, thus $query_update never gets set to anything.

0

wait no, you set $count in line 57 - but I would verify what $count is.

Edited by amac44: n/a

0

and even if count is set properly, that for loop will just set and re-set $query_update, so only one update query will execute. So really I would rewrite your lines 179-200 as something like this (without knowing exactly what you're trying to do)

if (mysql_num_rows($result) == 0) {
		echo "No rows found, nothing to print so am exiting";
		exit;
	}
	
	else {

		// Fetch record rows in $result by while loop and put them into $row.

		while($row = mysql_fetch_assoc($result)){

			//start a counter in order to number the input fields for each record
			for($i=0;$i<$count;$i++){
				// Update field "StatusChangeChoice", matching with "PlayerID" value by while loop.
				$query_update = "UPDATE tblplayers SET StatusChangeChoice = '$selectChoice' where PlayerID = '$player'";
				$update = mysql_query($query_update, $conn_ssfhl) or die(mysql_error());
				if (!$update) {
					$message = 'Invalid query: ' . mysql_error() . "\n";
					$message .= 'Whole query: ' . $query_update;
					die($message);
				}
			}
		}
		
	}
0

We are much closer now...the $count is giving me 21 rows which is correct and the message when the form is submitted returns"Thank you
--- Update Complete ---This is the query : "
I think the problem now is the update query variable on line 192 $SelectChoice is never posted as a variable. The variable should be coming from the "select" drop down on line 97, but I am unsure how to get it to post the selected choice variable from the form.

0

Well, couple other things. Should move hidden variable 'hideplayerID' (line 91) up above the for loop - line 76 immediately after <form> would be a good place. No need to repeat that over and over.

To get select[] into a PHP var is a little tricky because $_POST will be an array, but you won't really know which array elements goes with which playerID.

I think instead of using select[] I would use the playerid in the name of each select you're generating. Then use that name in $query_update so there's a unique update happening each time through the loop.

0

You mean like this?
<select name="playerid">
<option value="Active" selected="selected">Active</option>
<option value="Bench">Bench</option>
</select>
and this?
$query_update = "UPDATE tblplayers SET StatusChangeChoice = 'playerid' where PlayerID = '$player'";

0

I mean the while loop beginning at line 87 above generates a table row. Each table row contains a select. Each select should be uniquely named such that it can be mapped to the player occupying that row. So on line 97 <select name="select[]"> could be <select name="<?=$row?>"> (I just looked at my Yahoo fantasy baseball team and this is what their html in classic mode looks like)

and then

foreach ($_POST as $my_player_id) {
  $query_update = "UPDATE tblplayers SET StatusChangeChoice = '".$_POST[$my_player_id]."' where PlayerID = '$my_player_id'";
  mysql_query($query_update);
}

Something like that. Not tested by any means. Basically you're looping through the players and updating each player's status.

0

I must not be getting it....here is what it looks like now

        <select name="<?=$row['PlayerID']?>">
          <option value="Active" selected="selected">Active</option>
          <option value="Bench">Bench</option>
        </select>
and
      // Update field "StatusChangeChoice", matching with "PlayerID" value by while loop.
      foreach ($_POST as $my_player_id) {
      $query_update = "UPDATE tblplayers SET StatusChangeChoice = '".$_POST[$my_player_id]."' where PlayerID = '$my_player_id'";

      mysql_query($query_update);
      }

Edited by mike_2000_17: Fixed formatting

0

I think I understand why we are binding the playerID to the select name but am unclear how the selection made "Active" or "Bench" would be getting passed to the StatusChangeChoice in the db.

0

By naming the <select> with the player id, $_POST will contain id numbers and their associated values. So if you had 3 players with id 101, 102, 103, the data in $_POST could look like
"101"=>"Active"
"102"=>"Bench"
"103"=>"Active"
(I'm assuming there is nothing but IDs in $_POST -- like I don't think you would need hideplayerID anymore -- if there are other values in $_POST you would need to filter them out somehow)
So then the foreach is looping through that data and setting the status to Active for id 101, Bench for 102, Active for 103 etc.

If you want to post your latest code feel free.

Edited by amac44: clarification

0

Here it is:

<?php
session_start();

require('/conn_ssfhl.php'); 

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_DetailRS1 = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_DetailRS1 = $_SESSION['MM_Username'];
}
mysql_select_db($database_conn_ssfhl, $conn_ssfhl);
$query_DetailRS1 = sprintf("SELECT PlayerID, FanID, Type, InjuryID, Player, StatusID, StatusChangeChoice, CurrentWeek, GMEmail FROM tblplayers WHERE GMEmail = %s ORDER BY tblplayers.Type Asc", GetSQLValueString($colname_DetailRS1, "text"));
$DetailRS1 = mysql_query($query_DetailRS1, $conn_ssfhl) or die(mysql_error());
$row_DetailRS1 = mysql_fetch_assoc($DetailRS1);
$totalRows_DetailRS1 = mysql_num_rows($DetailRS1);


$colname_rsGMDetail = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_rsGMDetail = $_SESSION['MM_Username'];
}
mysql_select_db($database_conn_ssfhl, $conn_ssfhl);
$query_rsGMDetail = sprintf("SELECT GMFirst, GMLast FROM tbluseradmin WHERE GMEmail = %s", GetSQLValueString($colname_rsGMDetail, "text"));
$rsGMDetail = mysql_query($query_rsGMDetail, $conn_ssfhl) or die(mysql_error());
$row_rsGMDetail = mysql_fetch_assoc($rsGMDetail);
$totalRows_rsGMDetail = mysql_num_rows($rsGMDetail);

// Count rows in table
$count=mysql_num_rows($DetailRS1);

// Post variables
$player = $_POST['hideplayerID'];
$playerid = $_POST['PlayerID'];

if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>form</title>
</head>
<body bgcolor="#FFFFFF">
<form id="frmupdate" name="frmupdate" method="post" action="update2.php">
  <table width="500" border="0" cellspacing="1" cellpadding="0">
    <tr>
      <td align="center" bgcolor="#FFCC00"><strong>ID</strong></td>
      <td align="center" bgcolor="#FFCC00">Position</td>
      <td align="center" bgcolor="#FFCC00">Player</td>
      <td align="center" bgcolor="#FFCC00">Health</td>
      <td align="center" bgcolor="#FFCC00">Current Status</td>
      <td align="center" bgcolor="#FFCC00"><strong>Change Status</strong></td>
    </tr>
    <?php
// Fetch record rows in $DetailRS1 by while loop and put them into $row.
while($row=mysql_fetch_assoc($DetailRS1)){
?>
    <tr>
      <td bgcolor="#FFFFCC"><? echo $row['PlayerID']; ?></td>
      <td bgcolor="#FFFFCC"><? echo $row['Type']; ?></td>
      <td bgcolor="#FFFFCC"><? echo $row['Player']; ?></td>
      <td bgcolor="#FFFFCC"><? echo $row['InjuryID']; ?></td>
      <td bgcolor="#FFFFCC"><? echo $row['StatusID']; ?></td>
      <td bgcolor="#FFFFCC"><label>
        <select name=<?=$row['PlayerID']?>">
          <option value="Active" selected="selected">Active</option>
          <option value="Bench">Bench</option>
        </select>
      </label></td>
    </tr>
    <tr> </tr>
    <?php } // End while loop. ?>
  </table>
   <p>
                  <input type="submit" name="submit" value="submit" />
</p>
</form>

</body>
</html><?php
?>

Page 2
<?php require_once('../conn_ssfhl.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>update</title>
</head>
<body>
<?php
// If receive Submit button variable.
if($_POST['submit']){ 

// Select all data records in table "tblplayers" and put them into $result.
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
 # Script 2.5 - update.php

//Validate the status and combat Magic Quotes, if neccessary.
if (!empty($_REQUEST['select'])) {
$select = stripslashes($_REQUEST['select']);
} else {
$select = NULL;
echo '<p>You forgot to change your player status!</p>';
}

//If everything else is okay, print the message
echo "<p>Thank you</p>";

} 
else {//Selection was not made on form.
echo "<p>Please go back and complete your selections.</p>";
}

mysql_select_db($database_conn_ssfhl, $conn_ssfhl);
$query_result = "SELECT PlayerID FROM tblplayers ORDER BY PlayerID ASC";
$result = mysql_query($query_result, $conn_ssfhl) or die(mysql_error());
$row_result = mysql_fetch_assoc($result);
$totalRows_result = mysql_num_rows($result);

      if (mysql_num_rows($result) == 0) {
      echo "No rows found, nothing to print so am exiting";
      exit;

      }

       

      else {

       

      // Fetch record rows in $result by while loop and put them into $row.

       

      while($row = mysql_fetch_assoc($result)){

       

      //start a counter in order to number the input fields for each record
      for($i=0;$i<$count;$i++){

      // Update field "StatusChangeChoice", matching with "PlayerID" value by while loop.
      foreach ($_POST as $my_player_id) {
      $query_update = "UPDATE tblplayers SET StatusChangeChoice = '".$_POST[$my_player_id]."' where PlayerID = '$my_player_id'";
	  
      mysql_query($query_update);
      }
      if (!$update) {

      $message = 'Invalid query: ' . mysql_error() . "\n";
      $message .= 'Whole query: ' . $query_update;
      die($message);
      }
      }
      }
      }
//}
echo "--- Update Complete ---";

echo  "This is the query : ". $query_update;
?>
</body>
</html>
<?php
mysql_free_result($result);?>

Here is waht the submitted page now gives me....what do I do with this?
You forgot to change your player status!

Thank you
--- Update Complete ---This is the query : array(21) { ["2028""]=> string(6) "Active" ["1176""]=> string(6) "Active" ["1331""]=> string(6) "Active" ["842""]=> string(6) "Active" ["7816""]=> string(6) "Active" ["2769""]=> string(6) "Active" ["2392""]=> string(6) "Active" ["1916""]=> string(6) "Active" ["1976""]=> string(6) "Active" ["2131""]=> string(6) "Active" ["313""]=> string(6) "Active" ["1792""]=> string(6) "Active" ["1803""]=> string(5) "Bench" ["1859""]=> string(6) "Active" ["1714""]=> string(6) "Active" ["1556""]=> string(6) "Active" ["1321""]=> string(6) "Active" ["2394""]=> string(6) "Active" ["1268""]=> string(6) "Active" ["761""]=> string(6) "Active" ["submit"]=> string(6) "submit" } ?>

0

You're getting the You forgot thing because of: if (!empty($_REQUEST)) ... $_REQUEST does not contain select since you got rid of the original <select name="select"> ... actually I would just remove 157-163, doesn't look nec. to me.

That output below the content of $_POST? That would be surprising if it's the value of $query_update which should a valid sql string.

Also your if (!$update) doesn't make any sense because $update is never defined. You could move that whole block right under mysql_query($query_update) and change it to $update = mysql_query($query_update);

0

I made the changes you suggested and the form page is posting fine but I am getting this warning from the update page when the post is submitted.
Parse error: syntax error, unexpected $end in /home/ssfhl4/public_html/LoginFiles/update2.php on line 87

0

Here is the latest rendition of the two pages. I can get the array to print as a long string, but cannot get the update query to wk...is the array incorrect?

<?php
session_start();

require('/conn_ssfhl.php'); 

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_DetailRS1 = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_DetailRS1 = $_SESSION['MM_Username'];
}
mysql_select_db($database_conn_ssfhl, $conn_ssfhl);
$query_DetailRS1 = sprintf("SELECT PlayerID, FanID, Type, InjuryID, Player, StatusID, StatusChangeChoice, CurrentWeek, GMEmail FROM tblplayers WHERE GMEmail = %s ORDER BY tblplayers.Type Asc", GetSQLValueString($colname_DetailRS1, "text"));
$DetailRS1 = mysql_query($query_DetailRS1, $conn_ssfhl) or die(mysql_error());
$row_DetailRS1 = mysql_fetch_assoc($DetailRS1);
$totalRows_DetailRS1 = mysql_num_rows($DetailRS1);


$colname_rsGMDetail = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_rsGMDetail = $_SESSION['MM_Username'];
}
mysql_select_db($database_conn_ssfhl, $conn_ssfhl);
$query_rsGMDetail = sprintf("SELECT GMFirst, GMLast FROM tbluseradmin WHERE GMEmail = %s", GetSQLValueString($colname_rsGMDetail, "text"));
$rsGMDetail = mysql_query($query_rsGMDetail, $conn_ssfhl) or die(mysql_error());
$row_rsGMDetail = mysql_fetch_assoc($rsGMDetail);
$totalRows_rsGMDetail = mysql_num_rows($rsGMDetail);

// Count rows in table
$count=mysql_num_rows($DetailRS1);

if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>form</title>
</head>
<body bgcolor="#FFFFFF">
<form id="frmupdate" name="frmupdate" method="post" action="update2.php">
  <table width="500" border="0" cellspacing="1" cellpadding="0">
    <tr>
      <td align="center" bgcolor="#FFCC00"><strong>ID</strong></td>
      <td align="center" bgcolor="#FFCC00">Position</td>
      <td align="center" bgcolor="#FFCC00">Player</td>
      <td align="center" bgcolor="#FFCC00">Health</td>
      <td align="center" bgcolor="#FFCC00">Current Status</td>
      <td align="center" bgcolor="#FFCC00"><strong>Change Status</strong></td>
    </tr>
    <?php
// Fetch record rows in $DetailRS1 by while loop and put them into $row.
while($row=mysql_fetch_assoc($DetailRS1)){
?>
    <tr>
      <td bgcolor="#FFFFCC"><? echo $row['PlayerID']; ?></td>
      <td bgcolor="#FFFFCC"><? echo $row['Type']; ?></td>
      <td bgcolor="#FFFFCC"><? echo $row['Player']; ?></td>
      <td bgcolor="#FFFFCC"><? echo $row['InjuryID']; ?></td>
      <td bgcolor="#FFFFCC"><? echo $row['StatusID']; ?></td>
      <td bgcolor="#FFFFCC"><label>
        <select name="players[<?=$row['PlayerID']?>]">
          <option value="Active" selected="selected">Active</option>
          <option value="Bench">Bench</option>
</select>
      </label></td>
    </tr>
    <tr> </tr>
    <?php } // End while loop. ?>
  </table>
   <p>
                  <input type="submit" name="submit" value="submit" />
</p>
</form>

</body>
</html><?php
?>

Update Page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>update</title>
</head>
<body bgcolor="#FFFFFF">
<?php require_once('../conn_ssfhl.php'); ?>
<?php
// If receive Submit button variable.
if($_POST['submit']){ 
}
// Select all data records in table "tblplayers" and put them into $result.
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_conn_ssfhl, $conn_ssfhl);
$query_result = "SELECT PlayerID FROM tblplayers ORDER BY PlayerID ASC";
$result = mysql_query($query_result, $conn_ssfhl) or die(mysql_error());
$row_result = mysql_fetch_assoc($result);
$totalRows_result = mysql_num_rows($result);

      if (mysql_num_rows($result) == 0) {
      echo "No rows found, nothing to print so am exiting";
      exit;

      }

      else {

      // Fetch record rows in $result by while loop and put them into $row.

      while($row = mysql_fetch_assoc($result)){

      //start a counter in order to number the input fields for each record
      for($i=0;$i<$count;$i++){

      // Update field "StatusChangeChoice", matching with "PlayerID" value by while loop.
      foreach($_POST['players'] as   $playerid => $status) {
	  echo "Current value of \$playerid: $status.\n";
   	  $query_update = "UPDATE tblplayers SET StatusChangeChoice = '$status' WHERE PlayerID = '$playerid'";
   	  $update = mysql_query($query_update);
}
      if (!$update) {

      $message = 'Invalid query: ' . mysql_error() . "\n";
      $message .= 'Whole query: ' . $query_update;
      die($message);
      }
      }
      }
      }
echo "--- Update Complete ---";

echo  "This is the query : ". $query_update;
var_dump($_POST);
?>
</body>
</html>
0

On the update page, you are just updating these players, right? Is there any need to do a SELECT at all (e.g. if you're also displaying the roster again) ? I don't think so, I think you can lose the while and for loops.

GetSQLValueString isn't used, why not lose it. Or put it in some kind of global include file. Also lines 11-12 is just an empty if, not sure why that's in there. Might make sense to wrap the entire page in that.

So really it seems to me you could keep lines 1-9 and 64-75 and for output/debug 79-85 ... and delete the rest. And I'd move the check for successful $update inside the foreach. So then you'd have

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>update</title>
</head>
<body bgcolor="#FFFFFF">
<?php require_once('../conn_ssfhl.php'); ?>
<?php
// Update field "StatusChangeChoice", matching with "PlayerID" value
foreach($_POST['players'] as   $playerid => $status) {
	echo "Current value of \$playerid: $status.\n";
	$query_update = "UPDATE tblplayers SET StatusChangeChoice = '$status' WHERE PlayerID = '$playerid'";
	$update = mysql_query($query_update);
	if (!$update) {
		$message = 'Invalid query: ' . mysql_error() . "\n";
		$message .= 'Whole query: ' . $query_update;
		die($message);
	}
	echo "This is the query : ". $query_update . "<br>\n";
}
echo "--- Update Complete ---";

var_dump($_POST);
?>
</body>
</html>
0

I made the last round of changes you suggested and got a database error. It appears I was not referencing the database for the update query, so I fixed that. Pulled up the form, submitted it and it updated the database!
Thank you so much for all of you help with this project. Too many other folks would look at it, make a few suggestions and leave me with only partial answers. You stuck with it and solved the problems!

Thanks again,
Scott

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.