Results 1 to 4 of 4

Thread: Adding data to a mysql db with the help of loops (php) any takers?

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Posts
    82

    Talking Adding data to a mysql db with the help of loops (php) any takers?

    I have a form that was generated with the help of loops (I made it so I could select how many record sets I wanted to add at that time) So now I have this form that will display between 1 and 12 sets of text boxes (html) each with a value that is generated by the php script It works just fine.

    Now, that generated form must pass entered data to the next script that will add the form feilds into the database. This is where I am stuck. I got to the point to add fields to the database then did not have no clue where the loops would fit in.

    I am thinking that since I have 3 fields in each row that I would create a loop for each one of those to match its name.

    Right now I basicly have this in the form:

    Code:
    <?
    echo "
    <input type="text" name="abox$i"><br>
    <input type="text" name="bbox$i"><br>
    <input type="text" name="cbox$i"><br>
    ";
    
    ?>
    When the form is generated it spits out something like this (html view)

    Code:
    <input type="text" name="abox1"><br>
    <input type="text" name="bbox1"><br>
    <input type="text" name="cbox1"><br>
    
    <input type="text" name="abox2"><br>
    <input type="text" name="bbox2"><br>
    <input type="text" name="cbox2"><br>
    
    <input type="text" name="abox3"><br>
    <input type="text" name="bbox3"><br>
    <input type="text" name="cbox3"><br>
    Got it? I know its confusing

    But the big on is getting this stuff into the database with the help of loops.

    Here is the database stuff I got right now, I just need to know where to put the loops

    Code:
    <?
    
    // define the loops
    $a = 1;  // counts the number of "abox's"
    $b = 1;  // counts the number of "bbox's"
    $c = 1;  // counts the number of "cbox's"
    
    // database functions
    $db_name = "photos";
    $table_name = "data";
    $connection = @mysql_connect("localhost, xxxxx, xxxxx") or die ("cannot connect");
    
    $db = @mysql_select($db_name, $connection) or die ("cannot select");
    
    $sql = "
    INSERT INTO $table_name(set_id, locate, name)
    VALUES
    (\"$abox\", \"$bbox\", \"$cbox\")
    ";
    
    $result = @mysql_query($sql, $connection) or die ("cannot connect");
    
    ?>
    Thanks in advance!
    Last edited by evil_gamer; Oct 17th, 2001 at 11:05 PM.
    If you think I am wierd, then thats YOUR problem!

    -----------------------------------

    I keep snakes and lizards, wanna know more? PM me

Posting Permissions

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



Click Here to Expand Forum to Full Width