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);
?>