How do I insert textarea values one at a time into database?

I have a a simple form:
Select List - populated by a recordset that gets a list of technicians.   In this format:   Label - >  Tech name   Value - > Tech ID
Textarea - To paste zip codes into that the tech services.    In this format:   12345,12346,12347,etc..
When I want to submit the form, I want it to take all of those zip codes and insert them into the database as a single record each with the tech's id from the select list. 
The code I have is thus:
$zipcodes = explode(",", $_POST['textarea']);
$countZips = (count($zipcodes));
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
foreach($zipcodes as $key=>$value)
while ($countZips >= 1) {
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  $insertSQL = sprintf("INSERT INTO zip_zip (zip_code, tech_id) VALUES (%s, %s)",
                       GetSQLValueString($value, "int"),
                       GetSQLValueString($_POST['select'], "int"));
  mysql_select_db($database_localhost, $localhost);
  $Result1 = mysql_query($insertSQL, $localhost) or die(mysql_error());
          $countZips--;
//Done value exists
//Now moving to next page when done
          $insertGoTo = "index.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  header(sprintf("Location: %s", $insertGoTo));
//END
The issue is - let's say I paste 105 zip codes into the text area.   It will insert the FIRST zip code 105 times into the database instead of inserting the 105 zip codes individually.
Any idea what I'm doing wrong here?
Thanks!

Ok, so all of that mysql stuff just needs to be ran once until the connection is closed.  I didn't know that.  That probably makes it run better too.
Ok, so here is what that code looks like now.  There are a few additions because it turns out I also have to check to make sure the zip code is in a state that the tech is licensed in.  : (  I have a question about how to do that because it is different.  Do I need to post a new question or is better to ask here since my stuff is usually in left field?
Any way here is my code now.  I think it is much better, right?
//Start
//This is my recordset to get the last tech added
mysql_select_db($database_localhost, $localhost);
$query_getTechs = "SELECT * FROM zip_tech ORDER BY tech_id DESC";
$getTechs = mysql_query($query_getTechs, $localhost) or die(mysql_error());
$row_getTechs = mysql_fetch_assoc($getTechs);
$totalRows_getTechs = mysql_num_rows($getTechs);
//This is where I'm getting all zip codes that are serviceable by stupid regulations
mysql_select_db($database_localhost, $localhost);
$query_Recordset1 = "SELECT zip_code, state_prefix FROM zip_code";
$Recordset1 = mysql_query($query_Recordset1, $localhost) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
//ARRAYS
$results = array();
$states = array();
do {
  $results[] = $row_Recordset1['zip_code'];
  $states[] = $row_Recordset1['state_prefix'];
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
//Check if form is filled out
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
//If so, explode textarea values into an array or something
$zipcodes = explode(",", $_POST['textarea']);
//MySQL Stuff
mysql_select_db($database_localhost, $localhost);
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
//my loop to go through each zip code one by one
foreach($zipcodes as $value)
//Let's see if the value from the textarea is in our $results array from above
if (in_array($value, $results)){
//If it is in the array - then insert it into the database with the tech id
  $insertSQL = sprintf("INSERT INTO zip_zip (zip_code, tech_id) VALUES (%s, %s)",
                       GetSQLValueString($value, "int"),
                       GetSQLValueString($_POST['tech_id'], "int"));
  $Result1 = mysql_query($insertSQL, $localhost) or die(mysql_error());
//Done value exists
//Now moving to next page when done
          $insertGoTo = "index.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  header(sprintf("Location: %s", $insertGoTo));
//END
Message was edited by: Drymetal

Similar Messages

  • Insert a value of type Date/Time into a database

    I am trying to insert a value of type date time into an access database. What is the format needed to insert the date/time.
    Thanks,
    -Amos

    I had all kinds of problems getting a datetime inserted into a SQl Server DB. Probably similar so this is what I do:
    String date = new String("01/01/97 12:00:00");
    stmt.setObject(1, date);
    I tried using TimeStamp's but found I got an occasional Fractional Truncation exception back from the driver. Never had a problem inserting a String using the setObject() method though.
    Hope this helps

  • How can i insert more than one record a time in a JSP page?

    Hi experts,
    I'm working with JDeveloper version 3.2 application server 9i.
    I want to insert more than 1 record using a jsp page and then perform a commit at the end.
    do you can help me with this problem/challenge?
    Thank you,
    Regards,
    Mario

    statement.executeBatch() maybe?

  • How do I insert multiple simple objects at different times into a video, and see all of them?!

    I'm trying to make a very simple 20 second video clip of me hula hooping, and every 4 seconds, draw a circle around my hula hoop that remains there for the duration of the video. So at the beginning there will be 1 circle, at the end there will be 6. For some reason I can only figure out how to make one of these circles visible at a time. I've been googling and youtubing for the the past 2 hours and I can't find anything on how to do this?! It's very simple, i don't understand why I'm having such a hard time! Please help!

    Please read this FAQ for advice on how to ask your questions correctly for quicker and better answers:
    http://forums.adobe.com/thread/419981?tstart=0
    Thanks!

  • How can i pass the value one from to another form?

    hi all
    how can i pass the value one from to another form  with out use it when ever i want to needed this value that ican useit?
    like i have two fields U_test1 and U_test2  table name @AUSR
    that i have  four form  A! , A2,A3,A4    please tell me in details....?

    Hi,
    U can assign the values to some variables and access then in ur required forms.
    Vasu Natari.

  • How do I insert pages from one PDF into the current PDF in Acrobat X?

    I just upgraded from Acrobat 8 to Acrobat X.
    How do I insert pages from one PDF into the current PDF in Acrobat X pro?  I was able to do this from the Edit menu in Acrobat 8 pro.  Appreciate instructions.  Thanks.

    Hi chemadberk,
    In my Acrobat 8 Pro, Insert Pages is under the Document menu but anyway...
    In Acrobat X, click on the Tools pane(upper right side) then navigate to Pages- the Insert Pages commands are located there.
    Hope this helps,
    Dimitri
    [signature deleted by host]

  • How do I return two values from a stored procedure into an "Execute SQL Task" within SQL Server 2008 R2

    Hi,
    How do I return two values from a
    stored procedure into an "Execute SQL Task" please? Each of these two values need to be populated into an SSIS variable for later processing, e.g. StartDate and EndDate.
    Thinking about stored procedure output parameters for example. Is there anything special I need to bear in mind to ensure that the SSIS variables are populated with the updated stored procedure output parameter values?
    Something like ?
    CREATE PROCEDURE [etl].[ConvertPeriodToStartAndEndDate]
    @intPeriod INT,
    @strPeriod_Length NVARCHAR(1),
    @dtStart NVARCHAR(8) OUTPUT,
    @dtEnd NVARCHAR(8) OUTPUT
    AS
    then within the SSIS component; -
    Kind Regards,
    Kieran. 
    Kieran Patrick Wood http://www.innovativebusinessintelligence.com http://uk.linkedin.com/in/kieranpatrickwood http://kieranwood.wordpress.com/

    Below execute statement should work along the parameter mapping which you have provided. Also try specifying the parameter size property as default.
    Exec [etl].[ConvertPeriodToStartAndEndDate] ?,?,? output, ? output
    Add a script task to check ssis variables values using,
    Msgbox(Dts.Variables("User::strExtractStartDate").Value)
    Do not forget to add the property "readOnlyVariables" as strExtractStartDate variable to check for only one variable.
    Regards, RSingh

  • How to pass a default value in selection screen of logical database pnpce

    Dear All,
    Can any one tell me how to pass a default value in selection screen of logical database pnpce .
    Regards
    Rakesh Singh

    Hi Rakesh,
    Go to SE36 (logical database Builder).First enter PNPCE in Logical Database and press documentation,here you will get the details of exactly what is PNPCE and how it works.After that select selections in subojects in se36 only and enter display ,there you have the include from where you acn get the idea.
    Regards,
    Rahul

  • How I can save the value of a variable in a database?

    hello,
    how I can save the value of a variable in a database? I need to keep the # of times you press click animation. to know how many times it has been seen.
    I connect to msql database, using php, javascript, ajax and jquery, but not how to save the variable counter clicks from adobe edge Animate
    appreciate your help so I can connect to the database from adobe edge animate.
    thank you very much
    Luis Felipe Garcia
    [email protected]

    Hi, all-
    This isn't an Animate-specific issue, but I thought I'd take a stab at it anyway.  As with anything else on the web, you need to have a server script to handle incoming data, so it's all back end work.  Your page will need to call that script and provide parameters to that script that it can read.
    The easiest way I can think of to do this (and this is all highly theoretical, so please make sure it's secure before you implement it) is to create a 1px div that has visibility off.  Whenever you click, you can load your URL in that div, which then increments your counter on your db.
    Hope that helps inspire some interesting solutions!
    -Elaine

  • How to get DocSet property values in a SharePoint library into a CSV file using Powershell

    Hi,
    How to get DocSet property values in a SharePoint library into a CSV file using Powershell?
    Any help would be greatly appreciated.
    Thank you.
    AA.

    Hi AOK,
    Would you please post your current script and the issue for more effcient support.
    In addition, to manage document set in sharepoint please refer to this script to start:
    ### Load SharePoint SnapIn
    2.if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
    3.{
    4. Add-PSSnapin Microsoft.SharePoint.PowerShell
    5.}
    6.### Load SharePoint Object Model
    7.[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
    8.
    9.### Get web and list
    10.$web = Get-SPWeb http://myweb
    11.$list = $web.Lists["List with Document Sets"]
    12.
    13.### Get Document Set Content Type from list
    14.$cType = $list.ContentTypes["Document Set Content Type Name"]
    15.
    16.### Create Document Set Properties Hashtable
    17.[Hashtable]$docsetProperties = @{"DocumentSetDescription"="A Document Set"}
    18.$docsetProperties = @{"CustomColumn1"="Value 1"}
    19.$docsetProperties = @{"CustomColum2"="Value2"}
    20. ### Add all your Columns for your Document Set
    21.
    22.### Create new Document Set
    23.$newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($list.RootFolder,"Document Set Title",$cType.Id,$docsetProperties)
    24.$web.Dispose()
    http://www.letssharepoint.com/2011/06/document-sets-und-powershell.html
    If there is anything else regarding this issue, please feel free to post back.
    Best Regards,
    Anna Wang
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact [email protected]

  • How do I insert the value of an email field in the submit mailto: argument?

    I want to create a button that will redirect a PDF form to an email address entered as a field in the form.  In other words, a "return to sender" function.  The button function has a submit to URL where you can use "mailto:[email protected]".  How can I substitute the value from an email field in the form itself for the "[email protected]" value?

    You'll need to use JavaScript, and the mailDoc method in particular: http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.505.html
    Get the value of the field that contains the email address and use it as the value of the cTo property. See the following for a sample script: http://forums.adobe.com/message/3553628?tstart=-1

  • How do I insert several images at the same time?

    I'm wanting to insert several images onto a page. How do I do that? It only allows me to insert one at a time and I have over 100.

    If this is a once off exercise, you can speed things up in DW in Code View if you insert the code by hand.
    If the structure is identical (e.g. in a table), you can easily cut-and-paste the repetitive code and change the name of each file to suit.
    For example:
    <table>
    <tr>
    <td>image1.jpg</td>
    <td>image2.jpg</td>
    <td>image3.jpg</td>
    <td>image4.jpg</td>
    <td>image5.jpg</td>
    </tr>
    </table>
    However if you're doing this continually, as Nancy says, sounds like you might be better off with a 3rd party dedicated photo gallery tool or Dreamweaver extension, with a very efficient, automated front end for large numbers of images, whose code output you can insert into the Dreamweaver.
    There are plenty out there.

  • How do i send mass emails one at a time, without using CC or BCC

    In other words, I have a mailing list for my band. When I send emails to myself and bcc a bunch of emails, many people don't receive them or they get bounced to their junk mails. Is there a way to automate Mail so that an email can be sent, one at a time, to a large list of people? I've tried looking through the help document but it doesnt' help. Thanks!

    I am also looking for this solution.
    I update my address book every so often and on my PC was doing this with a software that sent individual emails in small batches overnight.
    How may I do this now that I'm on a Mac?

  • HT204411 i am trying to purchase many songs at one time. i have added all songs to wish list , now to purchase it will only let me  do one at a time  please advise how i can purchase more than one at a time

    i am trying to purchase many songs at one time. i have added all songs to wish list , now to purchase it will only let me  do one at a time  please advise how i can purchase more than one at a time

    There used to be a 'buy all' button on the wish list screen but for some reason that has been removed from the current version of iTunes so you will need to buy each item individually. You can try leaving feedback for Apple and maybe it'll be added back in a future update : http://www.apple.com/feedback/itunesapp.html

  • How can I insert a a chart made with Numbers, into a Pages document?

    Hallo. How can I insert a document of "pages" made a chart with "numbers"?

    Open the numbers file, select the chart, tap copy. Opne the Pages document, tap and hold for the menu, tap paste.

Maybe you are looking for

  • How to save data in a state machine.

    Need to save 2 data points in a state.  Or how to add both data points from state to the array that is saved in write to file vi.  Please use the vi for reference. Thank you for your help. DOG Attachments: State.zip ‏32 KB

  • Hi, my "adobe application manager" files are damaged, can't download

    Hi, my "adobe application manager" files are damaged, when I try to download an adobe application it just won't start because of that damaged "adobe application manager", I tried to find how to (re-)download/install "adobe application manager" but wi

  • Assignment of printers

    Hi all Here I am with one more. We are in SRM4.0 As of now we are able to assign printer at Pur grp level or Pur Org. level. But if we assign the printer in the attribute of buyer directly, the output device is not defaulted in Process purchase order

  • Lookup Query

    In Form Designer in OID grp form in properties tab In Lookup query I have tried giving option a,option b a)Select act_key from usr where usr_login='$Requester Information.User Login$' b)Select ACT_KEY from USR where USR.USR_LOGIN = '$Requester Inform

  • JTree + Setting Icon

    I have created a JTree that works fine. I wonder If there is a way of changing the tree icon of a specific leaf when I selected (Only that particular leaf). I tried few things with TreeRenderer but the best done was that I managed to change all the l