SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple inserts from form with 2 variables?

    I'm trying to figure this out. I want to insert multiple rows from a single form into mysql but I want to be able to insert 2 variables.

    Here is what I got:
    PHP Code:
    echo '<form method="post" action="updatelang.php">';
    $sql mysql_query("SELECT * FROM language WHERE lang = 'en' ORDER BY id");
    while(
    $row mysql_fetch_assoc($sql)){
        
        
    $snippetid $row['id'];
        
        echo 
    'Original Text: '.$row['text'].'<br>';
        echo 
    'New Text: <textarea name="thistext[]"></textarea>';
        
    }
    echo 
    '</form>'
    And here is my updatelang.php:¨
    PHP Code:
    foreach($_POST['thistext'] as $row){
        if(!empty(
    $row)){
            
    mysql_query("INSERT INTO language (fk_id,text) VALUES (???,'$row')");
        }

    Now what I want is to get the "$snippetid" with me into the foreach and into my INSERT but downt know how?

    Please help and Thanks in advance ;-)

  2. #2
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    336
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You can either put the $snippetid in thistext[$snippetid] or pass it in a hidden input

  3. #3
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by centered effect View Post
    You can either put the $snippetid in thistext[$snippetid] or pass it in a hidden input
    So if I do this: thistext['.$snippetid.'] how should I get the foreach($_POST['thistext'] as $row) out with the pair... ThisText and snippetid?

  4. #4
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    336
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    $_POST['thistext'] is the array, and $snippetid is the key, so it would be:

    foreach( $_POST['thistext'] as $k => $v )

    $k is the snippetid and $v is the text


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
  •