Forums
This topic is locked
Insert Multiple Records using Repeat Region
Posted 20 Apr 2007 23:20:49
1
has voted
20 Apr 2007 23:20:49 Robert Bruguera posted:
Hello and thank you all in advancedI building a softball team website for fun and I have a small problem. I want to input every players stats from one form and no matter what I do only the last player from the repeat region gets the input in the database.
Here's the code. I hope some can help me with this.
<pre id=code><font face=courier size=2 id=code>
<?php require_once('../Connections/brewcrewdb.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = ""
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "StatsAdd") {
$insertSQL = sprintf("INSERT INTO stats (roster_ID, game_ID, ab, `1b`, `2b`, `3b`, hr, bb, rbi, er, played) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['roster'], "int",
GetSQLValueString($_POST['gameID'], "int",
GetSQLValueString($_POST['ab'], "int",
GetSQLValueString($_POST['1b'], "int",
GetSQLValueString($_POST['2b'], "int",
GetSQLValueString($_POST['3b'], "int",
GetSQLValueString($_POST['hr'], "int",
GetSQLValueString($_POST['bb'], "int",
GetSQLValueString($_POST['rbi'], "int",
GetSQLValueString($_POST['er'], "int",
GetSQLValueString(isset($_POST['played']) ? "true" : "", "defined","1","0");
mysql_select_db($database_brewcrewdb, $brewcrewdb);
$Result1 = mysql_query($insertSQL, $brewcrewdb) or die(mysql_error());
$insertGoTo = "menu.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_brewcrewdb, $brewcrewdb);
$query_rsRoster = "SELECT rosterID, playerFirst, playerLast FROM roster ORDER BY playerNumber ASC";
$rsRoster = mysql_query($query_rsRoster, $brewcrewdb) or die(mysql_error());
$row_rsRoster = mysql_fetch_assoc($rsRoster);
$totalRows_rsRoster = mysql_num_rows($rsRoster);
$colname_rsGameDet = "-1";
if (isset($_GET['gameID'])) {
$colname_rsGameDet = (get_magic_quotes_gpc()) ? $_GET['gameID'] : addslashes($_GET['gameID']);
}
mysql_select_db($database_brewcrewdb, $brewcrewdb);
$query_rsGameDet = sprintf("SELECT games.gameID, games.inn1 + games.inn2 + games.inn3 + games.inn4 + games.inn5 + games.inn6 + games.inn7, games.inn1b + games.inn2b + games.inn3b + games.inn4b + games.inn5b + games.inn6b + games.inn7b, oteams.oTeam FROM games, schedule LEFT JOIN oteams ON schedule.team = oteams.oTeamID WHERE gameID = %s", $colname_rsGameDet);
$rsGameDet = mysql_query($query_rsGameDet, $brewcrewdb) or die(mysql_error());
$row_rsGameDet = mysql_fetch_assoc($rsGameDet);
$totalRows_rsGameDet = mysql_num_rows($rsGameDet);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="StatsAdd" name="StatsAdd" method="POST" action="<?php echo $editFormAction; ?>">
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="right"><strong><?php echo $row_rsGameDet['oTeam']; ?></strong></td>
<td> </td>
<td><?php echo $row_rsGameDet['games.inn1b + games.inn2b + games.inn3b + games.inn4b + games.inn5b + games.inn6b + games.inn7b']; ?></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td align="right"><strong>Brewcrew</strong></td>
<td> </td>
<td><?php echo $row_rsGameDet['games.inn1 + games.inn2 + games.inn3 + games.inn4 + games.inn5 + games.inn6 + games.inn7']; ?></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr align="center">
<td>Players</td>
<td>AB</td>
<td>1B</td>
<td>2B</td>
<td>3B</td>
<td>HR</td>
<td>BB</td>
<td>RBI</td>
<td>ER</td>
<td>Played</td>
</tr>
<tr align="center">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<?php do { ?>
<tr>
<td align="left"><?php echo $row_rsRoster['playerFirst']; ?> <?php echo $row_rsRoster['playerLast']; ?>
<input name="roster" type="hidden" id="roster" value="<?php echo $row_rsRoster['rosterID']; ?>" />
</td>
<td align="center"><input name="ab" type="text" id="ab" value="0" size="2" maxlength="2" /></td>
<td align="center"><input name="1b" type="text" id="1b" value="0" size="2" maxlength="2" /></td>
<td align="center"><input name="2b" type="text" id="2b" value="0" size="2" maxlength="2" /></td>
<td align="center"><input name="3b" type="text" id="3b" value="0" size="2" maxlength="2" /></td>
<td align="center"><input name="hr" type="text" id="hr" value="0" size="2" maxlength="2" /></td>
<td align="center"><input name="bb" type="text" id="bb" value="0" size="2" maxlength="2" /></td>
<td align="center"><input name="rbi" type="text" id="rbi" value="0" size="2" maxlength="2" /></td>
<td align="center"><input name="er" type="text" id="er" value="0" size="2" maxlength="2" /></td>
<td align="center"><input name="played" type="checkbox" id="played" value="1" checked="checked" /></td>
</tr>
<?php } while ($row_rsRoster = mysql_fetch_assoc($rsRoster)); ?>
<tr>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
</tr>
<tr>
<td align="left"><input name="gameID" type="hidden" id="gameID" value="<?php echo $row_rsGameDet['gameID']; ?>" /></td>
<td colspan="3" align="center"> </td>
<td colspan="3" align="center"> </td>
<td colspan="3" align="center"> </td>
</tr>
<tr>
<td align="left"><input type="submit" name="Submit" value="Next" /></td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="StatsAdd">
</form>
</body>
</html>
<?php
mysql_free_result($rsRoster);
mysql_free_result($rsGameDet);
?>
</font id=code></pre id=code>