Results 1 to 3 of 3

Thread: $_POST[] comma seperated string, exlode and explode again before insert into DB

  1. #1
    Join Date
    Aug 2011
    Posts
    27
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default $_POST[] comma seperated string, exlode and explode again before insert into DB

    Hi i have a comma separated. Each seperated value contains a string which is seperated by a "|".. I need to explode the second string and insert the multiple data into the dB..

    here is my code:



    here is my post data example:
    PHP Code:
    //    name|surname|acc@domain.com|contact,johnny|smith|jsmith@jjjjj.com|contact, and so on.. I need to insert the individual data into the db and if successful echo 1 else error..

    $contacts $_POST['conts'];
    if(!empty(
    $contacts)){
    $one[] = explode(',',$contacts);
    foreach(
    $one as $two){
    $three[] = explode('|'$two);
    foreach(
    $three as $four){
                
    $sql="INSERT INTO jos_mycont (`prop_userid`,`category`,`firstname`,`surname`,`email`) VALUES ('$thisJRUser->id','$four[3]','$four[0]','$four[1]','$four[2]')";
                
    mysql_query($sql,$contLink);
    }
            
                if (!
    mysql_query($sql,$contLink)){
                echo 
    "Unable to insert client details";
                exit;
                } else {
                echo 
    '1';
                exit;
                }     
    }
                } else {
                echo 
    'No contacts selected';
                exit;
                } 
    Last edited by jscheuer1; 02-02-2014 at 01:24 PM. Reason: Format

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Ok. Is there a question? Please be specific about what is not working in the code.
    Daniel - Freelance Web Design | <?php?> | <html>| espaņol | Deutsch | italiano | portuguęs | catalā | un peu de franįais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    You might look at the str_getcsv() function. Beyond that, you'd need to be more specific about what your question is.

Similar Threads

  1. explode
    By james438 in forum PHP
    Replies: 9
    Last Post: 03-22-2012, 07:05 AM
  2. Javascript for comma seperated list to radio buttons
    By lilpete in forum Looking for such a script or service
    Replies: 3
    Last Post: 09-17-2010, 02:30 PM
  3. Explode Function Help
    By DeSaaD37 in forum PHP
    Replies: 4
    Last Post: 03-16-2009, 05:59 PM
  4. Insert one string into another.
    By jlizarraga in forum JavaScript
    Replies: 19
    Last Post: 08-13-2008, 08:12 AM
  5. explode.js
    By chloedearest in forum JavaScript
    Replies: 7
    Last Post: 08-10-2006, 07:21 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •