|
-
Sep 27th, 2003, 02:53 PM
#1
Thread Starter
Hyperactive Member
Inserting multiple rows of data*RESOLVED*
I am trying to insert multiple rows of data at the same time by having the admin enter in all the information. its all going to the same table. i was wondering if there is a way to do it...? if you need to see how i am doing it now, ill show you if you ask.
Last edited by Muk108; Sep 30th, 2003 at 03:03 PM.
-
Sep 27th, 2003, 05:12 PM
#2
-
Sep 27th, 2003, 09:40 PM
#3
Thread Starter
Hyperactive Member
here is how i am diong it now...
PHP Code:
<?
if (isset($_POST['a_sbmt'])) {
$a_raceid = $_POST['a_meet_id'];
$a_rfname = $_POST['a_rfname'];
$a_rlname = $_POST['a_rlname'];
$a_time = $_POST['a_time'];
$a_grade = $_POST['a_grade'];
$a_cap = $_POST['a_cap'];
$a_var = $_POST['a_var'];
?>
<html><head><title>Data Inserted</title><META HTTP-EQUIV="Refresh" CONTENT="0; admin_times.php"></head><body><br />Thank You For Adding your information.<a href=admin_team.php>Click Here</a>to return.</body></html>
<?
$m_date = date("D M j G:i:s Y");//
$insert_meet = "INSERT INTO times (`times_id`,`times_raceid`,`times_rfname`,`times_rlname`,`times_time`,`times_grade`,`times_cap`,`times_var`) VALUES ('','$a_raceid','$a_rfname','$a_rlname','$a_time','$a_grade','$a_cap','$a_var')";
mysql_query($insert_meet) or die(mysql_error());
} else {
then it does the form stuff...
any i want it to first ask for how many entrys there are going to be then i want it to display my form that many times so i dont have to keep reloading the page. can ya help me with that?
-
Sep 28th, 2003, 10:38 AM
#4
Addicted Member
Sure you can
"INSERT INTO times (`times_id`,`times_raceid`, ...)
VALUES ('','$a_raceid1' , ...) , ('','$a_raceid2' , ...) , ..."
In your case, you could ask for how many records will be added, like you said, then enumerate the form field names:
record1:
...name=a_meet_id1
...
record2:
...name=a_meet_id2
...
record3:
...name=a_meet_id3
Then use...
$a_raceid1 = $_POST['a_meet_id1'];
$a_raceid2 = $_POST['a_meet_id2'];
$a_raceid3 = $_POST['a_meet_id3'];
along with your new multiple INSERT INTO statement (also dynamically created).
Circa 1995
Engineer - I think we should put our website address on our paper catalogs.
Vice President - Don't get too excited about this internet thing.
I am sorry, but the Oracle was mistaken. You cannot help us.
-Matrix video game
I'm doing a (free) operating system (just a hobby, won't be big and professional like gnu) for 386(486) AT clones. ... and it probably never will support anything other than AT-harddisks, as that's all I have :-(.
-Linus
Question. Do you know that the character "?" means I'm asking a question? Question. Do you know that spoken inflection also provides the same cue? So please don't say, "Question" before you ask your question. Believe me I'll know.
That said, I would have said this first if it had to precede what I'm telling you now. Having said that, what I'm telling you now is the same thing I just said about the annoying phrases "That said" and "Having said that".
Are you threatening me, Master Jedi?
-Chancellor Palpatine
-
Sep 28th, 2003, 12:25 PM
#5
This is probably written pretty poorly, but it works for what I think you want to do..
If you aren't sure what it does, check this out:
http://blast.complex-sys.com/php/mul.../multiform.php
Feel free to try it out, although I limited the $_GET['num'] value to 25 because I didn't want my server to get any 1000+ form requests..
Code:
<?
//set how many forms to show
if(isset($_GET['num']) && is_numeric($_GET['num']) && $_GET['num'] > 0){
$forms = $_GET['num'];
}else{
$forms = 1;
}
?>
<form method='get'>
Showing <input type='text' name='num' value='<?=$forms;?>' size='2'> forms <input type='submit' value='update'><br>
</form>
<hr width='25%' align='left'>
<?
$m_date = date("D M j G:i:s Y");
if(isset($_POST['a_sbmt'])){
//do nothing
}else{
echo "<form method='post'>\n";
}
for($i = 1; $i <= $forms; $i++){
if(isset($_POST['a_sbmt'])){
//define form variables
$a_raceid = $_POST['frm' . $i . '_a_meet_id'];
$a_rfname = $_POST['frm' . $i . '_a_rfname'];
$a_rlname = $_POST['frm' . $i . '_a_rlname'];
$a_time = $_POST['frm' . $i . '_a_time'];
$a_grade = $_POST['frm' . $i . '_a_grade'];
$a_cap = $_POST['frm' . $i . '_a_cap'];
$a_var = $_POST['frm' . $i . '_a_var'];
//construct MySQL query
$insert_meet = "INSERT INTO times ";
$insert_meet .= "(`times_id`,`times_raceid`,`times_rfname`,`times_rlname`,`times_time`,`times_grade`,`times_cap`,`times_var`) ";
$insert_meet .= "VALUES ('','$a_raceid','$a_rfname','$a_rlname','$a_time','$a_grade','$a_cap','$a_var')";
echo "form $i = submitted<br><br>";
// mysql_query($insert_meet) or die(mysql_error());
}else{
echo " <b>form $i</b><br><br>\n";
echo " <blockquote>\n";
echo " a_meed_id: <input type='text' name='frm" . $i . "_a_meet_id' size='4' maxlength='2'><br>\n";
echo " a_rfname: <input type='text' name='frm" . $i . "_a_rfname' size='15' maxlength='20'><br>\n";
echo " a_rlname: <input type='text' name='frm" . $i . "_a_rlname' size='15' maxlength='20'><br>\n";
echo " a_time: <input type='text' name='frm" . $i . "_a_time' size='10' maxlength='20'><br>\n";
echo " a_grade: <input type='text' name='frm" . $i . "_a_grade' size='5' maxlength='10'><br>\n";
echo " a_cap: <input type='text' name='frm" . $i . "_a_cap' size='10' maxlength='10'><br>\n";
echo " a_val: <input type='text' name='frm" . $i . "_a_var' size='10' maxlength='10'><br>\n";
echo " </blockquote>\n";
echo " <hr width='25%' align='left'>\n\n";
}
}
if(isset($_POST['a_sbmt'])){
//do nothing
}else{
echo " <br><br>\n";
echo " <input type='submit' name='a_sbmt' value='submit'>\n";
echo "</form>\n";
}
?>
Last edited by kows; Sep 28th, 2003 at 12:30 PM.
-
Sep 28th, 2003, 09:23 PM
#6
Thread Starter
Hyperactive Member
the maltiple forms parts works but it only inputs the first set, i acnt get it to input anymroe....
-
Sep 28th, 2003, 10:14 PM
#7
oh, hmm, maybe you should uncomment the query. I commented it out because I didn't actually set up a database and I would get an error if I didn't take it out, so that just might be your problem.
-
Sep 29th, 2003, 05:47 AM
#8
Thread Starter
Hyperactive Member
i did uncomment it but it only inputs the first form.
-
Sep 29th, 2003, 11:59 AM
#9
you could just not query it in the first loop, make the query into an array, and then query it later on.. sort of like this:
Code:
//construct MySQL query
$insert_meet[$i] = "INSERT INTO times ";
$insert_meet[$i] .= " (`times_id`,`times_raceid`,`times_rfname`,`times_rlname`,`times_time`,`times_grade`,`times_cap`,`tim
es_var`) ";
$insert_meet[$i] .= "VALUES ('','$a_raceid','$a_rfname','$a_rlname','$a_time','$a_grade','$a_cap','$a_var')";
and later on, after the FOR() loop and maybe even after the whole form is made, you can query the whole array
Code:
for($i = 0; $i < count($insert_meet); $i++){
mysql_query($insert_meet[$i]) or die(mysql_error());
}
I would test it myself but I'm at school right now and don't have access to an FTP client to upload scripts anywhere..
-
Sep 29th, 2003, 03:06 PM
#10
Thread Starter
Hyperactive Member
ok i fixed it the the inserts needed the [$i] but the mysql_query() didnt need the for statment.
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
|