I have a two page for to update multiple rows in one column of my database. The form appears ok, yet the data never updates, I am only left with blank rows...any suggestions on mis-named variables or is it something else.
Thanks for your help.
Page one code:
<?php require('/conn.php'); ?>
<?php
session_start();
?>
<?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;
}
}
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, $conn);
$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) 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);
// start a counter in order to number the input fields for each record
$i = 0;
?>
<body>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form id="form1" name="form1" method="post" action="update.php">
<td>
<tr class="statshdr">
<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>
<?
// Fetch record rows in $result 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="select<? echo $row['id'];?>" id="select<? echo $row['id'];?>"/>
<option value="Active" selected="selected">Active</option>
<option value="Bench">Bench</option>
</select>
</label>
</form>
</td>
</tr>
<? } // End while loop. ?>
</table>
<input type="submit" name="Submit" value="Update" />
</body>
update page code:
<?php require_once('../conn.php'); ?>
<?php
session_start();
// 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, $conn);
$query_result = "SELECT * FROM tblplayers ORDER BY Type ASC";
$result = mysql_query($query_result, $conn) or die(mysql_error());
$row_result = mysql_fetch_assoc($result);
$totalRows_result = mysql_num_rows($result);
if($_POST['Submit']){ // If receive Submit button variable.
// Fetch record rows in $result by while loop and put them into $row.
while($row=mysql_fetch_assoc($result)){
// Get the posted value "name_ID value" from form.php. This variable change it's value by while loop.
$select=$_POST["select".$row[id]];
// Update field "name", matching with "id" value by while loop.
mysql_query("UPDATE tblplayers SET StatusChangeChoice = '$select' where PlayerID = '$row[PlayerID]'");
}
echo "--- Update Complete ---";
}
?>
<body>
<p><?php //echo $select['$i'];
echo "<pre>";
var_dump($select);
echo "</pre>";
print_r($result);
var_dump($_POST);?> </p>
</body>