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 advanced
I 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>
&lt;?php require_once('../Connections/brewcrewdb.php'); ?&gt;
&lt;?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);
?&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form id="StatsAdd" name="StatsAdd" method="POST" action="&lt;?php echo $editFormAction; ?&gt;"&gt;
&lt;table width="600" border="0" cellspacing="0" cellpadding="0"&gt;
&lt;tr&gt;
&lt;td align="right"&gt;&lt;strong&gt;&lt;?php echo $row_rsGameDet['oTeam']; ?&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&lt;?php echo $row_rsGameDet['games.inn1b + games.inn2b + games.inn3b + games.inn4b + games.inn5b + games.inn6b + games.inn7b']; ?&gt;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align="right"&gt;&lt;strong&gt;Brewcrew&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&lt;?php echo $row_rsGameDet['games.inn1 + games.inn2 + games.inn3 + games.inn4 + games.inn5 + games.inn6 + games.inn7']; ?&gt;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr align="center"&gt;
&lt;td&gt;Players&lt;/td&gt;
&lt;td&gt;AB&lt;/td&gt;
&lt;td&gt;1B&lt;/td&gt;
&lt;td&gt;2B&lt;/td&gt;
&lt;td&gt;3B&lt;/td&gt;
&lt;td&gt;HR&lt;/td&gt;
&lt;td&gt;BB&lt;/td&gt;
&lt;td&gt;RBI&lt;/td&gt;
&lt;td&gt;ER&lt;/td&gt;
&lt;td&gt;Played&lt;/td&gt;
&lt;/tr&gt;
&lt;tr align="center"&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;td&gt;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;?php do { ?&gt;
&lt;tr&gt;
&lt;td align="left"&gt;&lt;?php echo $row_rsRoster['playerFirst']; ?&gt;&nbsp;&lt;?php echo $row_rsRoster['playerLast']; ?&gt;
&lt;input name="roster" type="hidden" id="roster" value="&lt;?php echo $row_rsRoster['rosterID']; ?&gt;" /&gt;
&nbsp;&lt;/td&gt;
&lt;td align="center"&gt;&lt;input name="ab" type="text" id="ab" value="0" size="2" maxlength="2" /&gt;&lt;/td&gt;
&lt;td align="center"&gt;&lt;input name="1b" type="text" id="1b" value="0" size="2" maxlength="2" /&gt;&lt;/td&gt;
&lt;td align="center"&gt;&lt;input name="2b" type="text" id="2b" value="0" size="2" maxlength="2" /&gt;&lt;/td&gt;
&lt;td align="center"&gt;&lt;input name="3b" type="text" id="3b" value="0" size="2" maxlength="2" /&gt;&lt;/td&gt;
&lt;td align="center"&gt;&lt;input name="hr" type="text" id="hr" value="0" size="2" maxlength="2" /&gt;&lt;/td&gt;
&lt;td align="center"&gt;&lt;input name="bb" type="text" id="bb" value="0" size="2" maxlength="2" /&gt;&lt;/td&gt;
&lt;td align="center"&gt;&lt;input name="rbi" type="text" id="rbi" value="0" size="2" maxlength="2" /&gt;&lt;/td&gt;
&lt;td align="center"&gt;&lt;input name="er" type="text" id="er" value="0" size="2" maxlength="2" /&gt;&lt;/td&gt;
&lt;td align="center"&gt;&lt;input name="played" type="checkbox" id="played" value="1" checked="checked" /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;?php } while ($row_rsRoster = mysql_fetch_assoc($rsRoster)); ?&gt;
&lt;tr&gt;
&lt;td align="center"&gt;&nbsp;&lt;/td&gt;
&lt;td align="center"&gt;&nbsp;&lt;/td&gt;
&lt;td align="center"&gt;&nbsp;&lt;/td&gt;
&lt;td align="center"&gt;&nbsp;&lt;/td&gt;
&lt;td align="center"&gt;&nbsp;&lt;/td&gt;
&lt;td align="center"&gt;&nbsp;&lt;/td&gt;
&lt;td align="center"&gt;&nbsp;&lt;/td&gt;
&lt;td align="center"&gt;&nbsp;&lt;/td&gt;
&lt;td align="center"&gt;&nbsp;&lt;/td&gt;
&lt;td align="center"&gt;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align="left"&gt;&lt;input name="gameID" type="hidden" id="gameID" value="&lt;?php echo $row_rsGameDet['gameID']; ?&gt;" /&gt;&lt;/td&gt;
&lt;td colspan="3" align="center"&gt;&nbsp;&lt;/td&gt;
&lt;td colspan="3" align="center"&gt;&nbsp;&lt;/td&gt;
&lt;td colspan="3" align="center"&gt;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align="left"&gt;&lt;input type="submit" name="Submit" value="Next" /&gt;&lt;/td&gt;
&lt;td align="center"&gt;&nbsp;&lt;/td&gt;
&lt;td align="center"&gt;&nbsp;&lt;/td&gt;
&lt;td align="center"&gt;&nbsp;&lt;/td&gt;
&lt;td align="center"&gt;&nbsp;&lt;/td&gt;
&lt;td align="center"&gt;&nbsp;&lt;/td&gt;
&lt;td align="center"&gt;&nbsp;&lt;/td&gt;
&lt;td align="center"&gt;&nbsp;&lt;/td&gt;
&lt;td align="center"&gt;&nbsp;&lt;/td&gt;
&lt;td align="center"&gt;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

&lt;input type="hidden" name="MM_insert" value="StatsAdd"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;?php
mysql_free_result($rsRoster);

mysql_free_result($rsGameDet);
?&gt;
</font id=code></pre id=code>

Reply to this topic