|
-
Oct 17th, 2001, 11:00 PM
#1
Thread Starter
Lively Member
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 
-
Oct 18th, 2001, 02:52 AM
#2
Conquistador
PHP Code:
<?
// define the loops
$a = 3; // The number of boxes in one group. I.e. 3
// database functions
$db_name = "photos";
$table_name = "data";
$connection = @mysql_connect("", "", "") or die ("cannot connect");
$db = @mysql_select($db_name, $connection) or die ("cannot select");
for($i = 1; $a; i++){
$sql = "INSERT INTO $table_name(set_id, locate, name)
VALUES ('$abox$i', '$bbox$i', '$cbox$i')";
$result = @mysql_query($sql, $connection) or die ("cannot connect");
}
mysql_close ();
?>
Try that
-
Oct 18th, 2001, 03:07 PM
#3
Originally posted by da_silvy
PHP Code:
<?
// define the loops
$a = 3; // The number of boxes in one group. I.e. 3
// database functions
$db_name = "photos";
$table_name = "data";
$connection = @mysql_connect("", "", "") or die ("cannot connect");
$db = @mysql_select($db_name, $connection) or die ("cannot select");
for($i = 1; $a; i++){
$sql = "INSERT INTO $table_name(set_id, locate, name)
VALUES ('$abox$i', '$bbox$i', '$cbox$i')";
$result = @mysql_query($sql, $connection) or die ("cannot connect");
}
mysql_close ();
?>
Try that
didn't you forget something da_silvy
for($i = 1; $i<$a; i++){
-
Oct 18th, 2001, 05:28 PM
#4
Conquistador
woops,
yes yes
sorry
PHP Code:
<?
// define the loops
$a = 3; // The number of boxes in one group. I.e. 3
$a++;
// database functions
$db_name = "photos";
$table_name = "data";
$connection = @mysql_connect("", "", "") or die ("cannot connect");
$db = @mysql_select($db_name, $connection) or die ("cannot select");
for($i = 1; $i<$a; i++){
$sql = "INSERT INTO $table_name(set_id, locate, name)
VALUES ('$abox$i', '$bbox$i', '$cbox$i')";
$result = @mysql_query($sql, $connection) or die ("cannot connect");
}
mysql_close ();
?>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|