473,749 Members | 2,394 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Auto-increment field not letting me insert multiple records at once

chumlyumly
9 New Member
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_grou ps', 'committee_inte rest' and 'committee_memb er' until recently.

After creating this insert page, I had to add an auto-increment key field to the 'specialty_grou ps' 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_grou p' table, I can only insert one record. The 'committee_inte rest' and 'committee_memb er' tables are still inputting multiple records just fine.

So, I figured it was because I added the auto-increment key field to the 'specialty_grou p' table. But the confusing thing is that when a user is updating his info, he/she can add as many 'specialty_grou p' 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:
Expand|Select|Wrap|Line Numbers
  1. <?php require_once('../Connections/connection.php'); ?>
  2. <?php
  3. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
  4. {
  5.   $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
  6.  
  7.   switch ($theType) {
  8.     case "text":
  9.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  10.       break;    
  11.     case "long":
  12.     case "int":
  13.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  14.       break;
  15.     case "double":
  16.       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  17.       break;
  18.     case "date":
  19.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  20.       break;
  21.     case "defined":
  22.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  23.       break;
  24.   }
  25.   return $theValue;
  26. }
  27.  
  28. //code here for inserting fields into the 'member' table.
  29.  
  30. $editFormAction = $_SERVER['PHP_SELF'];
  31. if (isset($_SERVER['QUERY_STRING'])) {
  32.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  33.  
  34. }
  35.  
  36. // loop through array of commmbr[] and write each instance to db
  37. @reset($commmbr);
  38. mysql_select_db($database_connection, $connection);
  39. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "memberinfo"));
  40. while (list($key, $val) = @each ($commmbr)) {
  41.   $insertSQL = sprintf("INSERT INTO committee_member (commmbr, member_id) VALUES (%s,LAST_INSERT_ID())",
  42.                        GetSQLValueString($val, "text"),
  43.                        GetSQLValueString($_REQUEST['member_id'], "int"));
  44.  
  45.   mysql_select_db($database_connection, $connection);
  46.   $Result1 = mysql_query($insertSQL, $connection) or die(mysql_error());
  47. }
  48.  
  49. $editFormAction = $_SERVER['PHP_SELF'];
  50. if (isset($_SERVER['QUERY_STRING'])) {
  51.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  52.  
  53. }
  54.  
  55. @reset($commint);
  56. mysql_select_db($database_connection, $connection);
  57. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "memberinfo"));
  58. while (list($key, $val) = @each ($commint)) {
  59.   $insertSQL = sprintf("INSERT INTO committee_interest (commint, member_id) VALUES (%s,LAST_INSERT_ID())",
  60.                        GetSQLValueString($val, "text"),
  61.                        GetSQLValueString($_REQUEST['member_id'], "int"));
  62.  
  63.   mysql_select_db($database_connection, $connection);
  64.   $Result1 = mysql_query($insertSQL, $connection) or die(mysql_error());
  65. }
  66. $editFormAction = $_SERVER['PHP_SELF'];
  67. if (isset($_SERVER['QUERY_STRING'])) {
  68.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  69.  
  70. }
  71. // loop through array of specialty[] and write each instance to db
  72. @reset($specialty);
  73. mysql_select_db($database_connection, $connection);
  74. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "memberinfo"));
  75. while (list($key, $val) = @each ($specialty)) {
  76.   $insertSQL = sprintf("INSERT INTO specialty_group (specialty, member_id) VALUES (%s,LAST_INSERT_ID())",
  77.                        GetSQLValueString($val, "text"),
  78.                        GetSQLValueString($_REQUEST['member_id'], "int"));
  79.  
  80.   mysql_select_db($database_connection, $connection);
  81.   $Result1 = mysql_query($insertSQL, $connection) or die(mysql_error());
  82. }
  83.  
  84. $colname_rs_member = "-1";
  85. if (isset($_GET['recordID'])) {
  86.   $colname_rs_member = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']);
  87. }
  88. mysql_select_db($database_connection, $connection);
  89. $query_rs_member = sprintf("SELECT * FROM member WHERE member_id = %s", $colname_rs_member);
  90. $rs_member = mysql_query($query_rs_member, $connection) or die(mysql_error());
  91. $row_rs_member = mysql_fetch_assoc($rs_member);
  92. $totalRows_rs_member = mysql_num_rows($rs_member);
  93.  
  94. $colname_rscommitteemember = "-1";
  95. if (isset($_GET['recordID'])) {
  96.   $colname_rscommitteemember = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']);
  97. }
  98. mysql_select_db($database_connection, $connection);
  99. $query_rscommitteemember = sprintf("SELECT * FROM committee_member WHERE member_id = %s", $colname_rscommitteemember);
  100. $rscommitteemember = mysql_query($query_rscommitteemember, $connection) or die(mysql_error());
  101. $row_rscommitteemember = mysql_fetch_assoc($rscommitteemember);
  102. $totalRows_rscommitteemember = mysql_num_rows($rscommitteemember);
  103.  
  104. $colname_rscommitteeinterest = "-1";
  105. if (isset($_GET['recordID'])) {
  106.   $colname_rscommitteeinterest = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']);
  107. }
  108. mysql_select_db($database_connection, $connection);
  109. $query_rscommitteeinterest = sprintf("SELECT * FROM committee_interest WHERE member_id = %s", $colname_rscommitteeinterest);
  110. $rscommitteeinterest = mysql_query($query_rscommitteeinterest, $connection) or die(mysql_error());
  111. $row_rscommitteeinterest = mysql_fetch_assoc($rscommitteeinterest);
  112. $totalRows_rscommitteeinterest = mysql_num_rows($rscommitteeinterest);
  113.  
  114. $colname_rsspecialty = "-1";
  115. if (isset($_GET['recordID'])) {
  116.   $colname_rsspecialty = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']);
  117. }
  118. mysql_select_db($database_connection, $connection);
  119. $query_rsspecialty = sprintf("SELECT * FROM specialty_group WHERE member_id = %s", $colname_rsspecialty);
  120. $rsspecialty = mysql_query($query_rsspecialty, $connection) or die(mysql_error());
  121. $row_rsspecialty = mysql_fetch_assoc($rsspecialty);
  122. $totalRows_rsspecialty = mysql_num_rows($rsspecialty);
  123. ?>
  124.  
Many, many thanks to anyone who can help. Please let me know if you have any further questions or if anything is unclear.

Charity
Aug 24 '07 #1
0 4453

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2606
by: Manlio Perillo | last post by:
Hi. This post follows "does python have useless destructors". I'm not an expert, so I hope what I will write is meaningfull and clear. Actually in Python there is no possibility to write code that follows C++ RAII pattern. Of course Python objects are not statics like in C++, but in C++ the auto_ptr class is used for enforcing this pattern for dynamical
1
34320
by: Lew | last post by:
Hi all, I'm trying to create a page that has a user-selectable page auto-refresh option (IE 5.5). Essentially, it's a page that contains a checkbox, when the user checks the checkbox, I'd like the page to auto-refresh every 4 seconds....if the user un-checks the checkbox, I'd like to turn off the auto refresh. The page is as follows:
5
6114
by: Robert Downes | last post by:
I'm using the following in a page that I'm testing in Mozilla: p.actionLinkBlock {border: 1px #000000 dashed; padding: 0.2cm; width: auto} But the dashed border is extending to the right-edge of the screen. I want it to only extend as far as it needs to to nicely contain the content within (a couple of links). Is width: auto the wrong property to do this? Is Mozilla rendering the style wrong?
20
2870
by: Vijay Kumar R. Zanvar | last post by:
Hello, Unlike register, auto keyword can not be used to declare formal parameter(s). Is there any specific reason for this? Kind regards, Vijay Kumar R. Zanvar
5
5043
by: Samuel | last post by:
Hi, I am running into a problem of mixing UICulture = auto and allowing users to select culture using a dropdown list. I am detecting a querystring, "setlang", and when found, setting the CurrentUICulture to what's specified in the querystring. Since I want to allow UICulture auto detecting, I add UICulture = "auto" to page directive on each page.
5
3275
by: maya | last post by:
at work they decided to center divs thus: body {text-align:center} #content {width: 612px; text-align:left; margin: 0 auto 0 auto; } this works fine in IE & FF, EXCEPT in FF it doesn't work if I change 'auto' to 0 for left and right margin values; I have to leave those at 'auto'.. so I would like to know what exactly means 'auto' -- what value it represents exactly (and does it apply for all elements/values you might apply 'auto' to?)
22
3082
by: nospam_news | last post by:
I currently get asked about my usage of "auto". What is it for? The keyword is clearly superflous here. In contrast to the huge majority of C/C++ developers I write definitions very explicitly like that: int main(char argc, char *argv, char *env) { try { auto Exception mainException(1); mainException.setErrNo(42);
2
3079
by: Piotr K | last post by:
Hi, I've encountered a strange problem with Firefox which I don't have any idea how to resolve. To the point: I've <divelement with a style "height: auto" and I want to retrieve this value ("auto") in JavaScript - however instead of getting "auto" value, I get calculated height. In IE and Opera it simply returns "auto". Any ideas how to check in Firefox if element height was set to "auto" ? I'll be grateful for any help.
1
2980
by: neridaj | last post by:
Hello, I've found a few postings of this problem but none of the answers seem to fix my problem. I have a content div wrapped around a left floated image and a right floated table. I want the table to dictate the height to the content div instead of popping out of the bottom of the content div. Seems pretty simple but too complicated for me I guess. If you know how to achieve this please share. Thanks, J /*begin code*/
21
6352
by: JOYCE | last post by:
Look the subject,that's my problem! I hope someone can help me, thanks
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6800
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.