SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    UK
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Insert loop problems. Tearing hair out!!

    Hi all
    I have created a dynamic for on a loop that works perfectly. On submission to this script I am having a problem getting the count value of the $x to increment accordingly. If I use the form and insert GetSQLValueString($_POST['track_name[1]'], "text"),GetSQLValueString($_POST['track_name[2]'], "text"), etc the entries are put to mysql perfectly but when using the variable $x the names do not increment. I have tried all manner of methods to get this and many pre written scripts to work, but have yet tio find anything which will show an increment for the count. If anyone can help I would appreciate it.

    Thanks in advance.


    PHP Code:
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

    //conditional loop
    if (isset($_POST['send'])) 

    $send $_POST['send']; 

    else 

    exit(); 
    }  
    for (
    $x 1$x <= $send$x++) 
    {

     
    $insertSQL sprintf("INSERT INTO metal_tracks (disco_id, track_name) VALUES (%s, %s)",
                           
    GetSQLValueString($_POST['disco_id'], "int"),
                           
    GetSQLValueString($_POST['track_name[$x]'], "text"));
     
     
    mysql_select_db($database_SiteConn$SiteConn);
      
    $Result1 mysql_query($insertSQL$SiteConn) or die(mysql_error());
    }

    //end loop
     
      
     
    $insertGoTo "";
      if (isset(
    $_SERVER['QUERY_STRING'])) {
        
    $insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
        
    $insertGoTo .= $_SERVER['QUERY_STRING'];
      }
      
    header(sprintf("Location: %s"$insertGoTo));


  2. #2
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    uk
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My first comment is that you have a lot going on at $insertSQL=!! Which is great and optimized for speed as long as it works


    Less optimally but better for your time, you could do the sprintf and GetSQLValueString in stages and then check each one.

    At a guess - and I mean guess removing the quotes round 'track_name[$x]'or replacing them with double quotes MIGHT work.

    Steve
    When all else fails, persistence prevails
    UK House Prices

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    UK
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the response. I have tried that though.

    When all else fails, persistence prevails, exept in loops.

  4. #4
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    uk
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WellBaffled
    Thanks for the response. I have tried that though.
    OK well I go back to my 'baby steps' suggestion then because:

    HTML Code:
    [font=Courier New][color=#dd0000]"INSERT INTO metal_tracks (disco_id, track_name) VALUES ([font=Courier New][color=#dd0000]'$disco_id','$[/color][/font][font=Courier New][color=#dd0000]track_name')"[/color][/font]
    [/color][/font]

    will work, and the functions, or getting the array values in is screwing you up.

    Doing each step singly, and echoing some temp variables is a pain in the a** and looks untidy but it's never failed me yet. Good luck!!
    Steve
    When all else fails, persistence prevails
    UK House Prices

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    UK
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I sorted it now thanks steve. Took some doing as the original code a Dreamweaver offering. Yes your above did work, I knew that already as I had tested many methods of inserting un numbered fields to test the form loop and the insert loop. I knew the loop was cycling perfectly just couldnt get $x to add to the insert field.

    Perhaps you may like to tackle my other query on this page. Between dates.


    Thanks again for your input steve. It was something you said initially that put me in kinda the right direction. The form is now live on server and functioning well.

  6. #6
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    uk
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WellBaffled
    Thanks again for your input steve. It was something you said initially that put me in kinda the right direction. The form is now live on server and functioning well.
    You are welcome. I just remembered why I like to post here. Apart from it helping me learn.
    Steve
    When all else fails, persistence prevails
    UK House Prices


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
  •