insert into db question [solved]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
reverend_ink
Forum Contributor
Posts: 151
Joined: Sun Apr 20, 2003 1:18 am
Location: Las Vegas | London

insert into db question [solved]

Post by reverend_ink »

Hi everyone, I am needing to finalise a bit of code and havent done this before and wondering how I would go about it. I have checked google but results coming up dont answer the question, so thought I would ask real people... ;)

Thanks in advance...

Now onto the question.

I have a form where a user inputs a numeric value (i.e. 1,2,3 etc) and upon submission I want it to generate an insert a string into the database for each of the values entered (i.e. enter 2 and the result will INSERT jkdfij00 once and 2309029jjj for the second entry).

I hope I am making myself clear enough.

Thanks everyone!
Last edited by reverend_ink on Fri Mar 25, 2005 1:21 pm, edited 1 time in total.
User avatar
pthomas
Forum Commoner
Posts: 68
Joined: Wed Jan 19, 2005 11:28 am
Location: Cincinnati, OH

Post by pthomas »

So you're saying that if the user enters in the number 5 then you want to insert five strings into the DB?

I'm not sure if thats what you're going for or not.

Paul
reverend_ink
Forum Contributor
Posts: 151
Joined: Sun Apr 20, 2003 1:18 am
Location: Las Vegas | London

Post by reverend_ink »

pthomas wrote:So you're saying that if the user enters in the number 5 then you want to insert five strings into the DB?

I'm not sure if thats what you're going for or not.

Paul
Close.

The script needs to take a numeric posted variable (5) and then on submit insert the same number of times as the variable.

This will insert a random value into the db but has to post a random key the same number of times as the posted numeric variable.
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

Post by Pyrite »

Just use a loop to call the same insert query that many times, each time dynamically putting something different in the insert query.
reverend_ink
Forum Contributor
Posts: 151
Joined: Sun Apr 20, 2003 1:18 am
Location: Las Vegas | London

Post by reverend_ink »

Pyrite wrote:Just use a loop to call the same insert query that many times, each time dynamically putting something different in the insert query.
thats what I am asking for. This is an area I have not done before.

Regards
User avatar
pthomas
Forum Commoner
Posts: 68
Joined: Wed Jan 19, 2005 11:28 am
Location: Cincinnati, OH

Post by pthomas »

try something like this:

Code: Select all

//Get the passed user value
$loop = $_POST['user_number'];

    //Loop the specified number of times
for ($ctr = 0; $ctr < $loop; $ctr++) {
     do something
     do something else
}
For more info on php functions, look at
http://us4.php.net/manual/en/control-st ... oreach.php

Paul
Post Reply