Hello scripters -
OS: Mac OSX
Language: PHP w/ MySQL database
I've created an insert page where a user inputs his info, which then goes to four different tables in a MySQL database. The tables are all linked with the field 'member_id', which is an auto-increment field in the parent table ('members').
I've been able to input multiple records into the other three tables 'specialty_groups', 'committee_interest' and 'committee_member' until recently.
After creating this insert page, I had to add an auto-increment key field to the 'specialty_groups' table so that users could go in and delete or make updates to their specialty choices (in the update pages).
The trouble is, now when I go to insert specialty records into the 'specialty_group' table, I can only insert one record. The 'committee_interest' and 'committee_member' tables are still inputting multiple records just fine.
So, I figured it was because I added the auto-increment key field to the 'specialty_group' table. But the confusing thing is that when a user is updating his info, he/she can add as many 'specialty_group' fields as he/she wants - on the update page. (However, on that page, the 'member_id' field is taken from a session variable 'username' from the 'member' table).
My code for the insert page is below:
-
<?php require_once('../Connections/connection.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;
-
}
-
-
//code here for inserting fields into the 'member' table.
-
-
$editFormAction = $_SERVER['PHP_SELF'];
-
if (isset($_SERVER['QUERY_STRING'])) {
-
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
-
-
}
-
-
// loop through array of commmbr[] and write each instance to db
-
@reset($commmbr);
-
mysql_select_db($database_connection, $connection);
-
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "memberinfo"));
-
while (list($key, $val) = @each ($commmbr)) {
-
$insertSQL = sprintf("INSERT INTO committee_member (commmbr, member_id) VALUES (%s,LAST_INSERT_ID())",
-
GetSQLValueString($val, "text"),
-
GetSQLValueString($_REQUEST['member_id'], "int"));
-
-
mysql_select_db($database_connection, $connection);
-
$Result1 = mysql_query($insertSQL, $connection) or die(mysql_error());
-
}
-
-
$editFormAction = $_SERVER['PHP_SELF'];
-
if (isset($_SERVER['QUERY_STRING'])) {
-
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
-
-
}
-
-
@reset($commint);
-
mysql_select_db($database_connection, $connection);
-
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "memberinfo"));
-
while (list($key, $val) = @each ($commint)) {
-
$insertSQL = sprintf("INSERT INTO committee_interest (commint, member_id) VALUES (%s,LAST_INSERT_ID())",
-
GetSQLValueString($val, "text"),
-
GetSQLValueString($_REQUEST['member_id'], "int"));
-
-
mysql_select_db($database_connection, $connection);
-
$Result1 = mysql_query($insertSQL, $connection) or die(mysql_error());
-
}
-
$editFormAction = $_SERVER['PHP_SELF'];
-
if (isset($_SERVER['QUERY_STRING'])) {
-
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
-
-
}
-
// loop through array of specialty[] and write each instance to db
-
@reset($specialty);
-
mysql_select_db($database_connection, $connection);
-
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "memberinfo"));
-
while (list($key, $val) = @each ($specialty)) {
-
$insertSQL = sprintf("INSERT INTO specialty_group (specialty, member_id) VALUES (%s,LAST_INSERT_ID())",
-
GetSQLValueString($val, "text"),
-
GetSQLValueString($_REQUEST['member_id'], "int"));
-
-
mysql_select_db($database_connection, $connection);
-
$Result1 = mysql_query($insertSQL, $connection) or die(mysql_error());
-
}
-
-
$colname_rs_member = "-1";
-
if (isset($_GET['recordID'])) {
-
$colname_rs_member = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']);
-
}
-
mysql_select_db($database_connection, $connection);
-
$query_rs_member = sprintf("SELECT * FROM member WHERE member_id = %s", $colname_rs_member);
-
$rs_member = mysql_query($query_rs_member, $connection) or die(mysql_error());
-
$row_rs_member = mysql_fetch_assoc($rs_member);
-
$totalRows_rs_member = mysql_num_rows($rs_member);
-
-
$colname_rscommitteemember = "-1";
-
if (isset($_GET['recordID'])) {
-
$colname_rscommitteemember = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']);
-
}
-
mysql_select_db($database_connection, $connection);
-
$query_rscommitteemember = sprintf("SELECT * FROM committee_member WHERE member_id = %s", $colname_rscommitteemember);
-
$rscommitteemember = mysql_query($query_rscommitteemember, $connection) or die(mysql_error());
-
$row_rscommitteemember = mysql_fetch_assoc($rscommitteemember);
-
$totalRows_rscommitteemember = mysql_num_rows($rscommitteemember);
-
-
$colname_rscommitteeinterest = "-1";
-
if (isset($_GET['recordID'])) {
-
$colname_rscommitteeinterest = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']);
-
}
-
mysql_select_db($database_connection, $connection);
-
$query_rscommitteeinterest = sprintf("SELECT * FROM committee_interest WHERE member_id = %s", $colname_rscommitteeinterest);
-
$rscommitteeinterest = mysql_query($query_rscommitteeinterest, $connection) or die(mysql_error());
-
$row_rscommitteeinterest = mysql_fetch_assoc($rscommitteeinterest);
-
$totalRows_rscommitteeinterest = mysql_num_rows($rscommitteeinterest);
-
-
$colname_rsspecialty = "-1";
-
if (isset($_GET['recordID'])) {
-
$colname_rsspecialty = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']);
-
}
-
mysql_select_db($database_connection, $connection);
-
$query_rsspecialty = sprintf("SELECT * FROM specialty_group WHERE member_id = %s", $colname_rsspecialty);
-
$rsspecialty = mysql_query($query_rsspecialty, $connection) or die(mysql_error());
-
$row_rsspecialty = mysql_fetch_assoc($rsspecialty);
-
$totalRows_rsspecialty = mysql_num_rows($rsspecialty);
-
?>
-
Many, many thanks to anyone who can help. Please let me know if you have any further questions or if anything is unclear.
Charity