Jump to content

Inserting multiple rows


timmah1

Recommended Posts

I'm trying to get each value to insert into it's own row, I'm sure this is simple, but I can't figure it out.

Right now, it inserts every value on the same line

id    username

10 test, test1, test2

 

I need it to insert everything separately

id  username

10 test

10 test1

10 test2

 

Here is my code

$usernames = implode(", ", $username);

		for ($i = 0; $i < count($usernames); $i++) {	

				mysql_query("INSERT INTO johns_username (id, username) VALUES('$UID','$usernames') ") 
				or die(mysql_error()); 
		}

 

Can anybody help me out?

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/201501-inserting-multiple-rows/
Share on other sites

ok, let me try again.

I used implode to see if I was getting all the names, which it echoes every name that is sent properly

 

I have a form which allows you to add more than one username

<input name="username[]" type="text" id="username[]" size="50" />

 

I then want each username to be in its own row, right now, it is inserting all the usernames in the same row

 

$count = count($_POST['username']);
		for ($i = 0; $i < $count; $i++) {
  
		   $username = $_POST['username'][$i]; 
		           
               mysql_query("INSERT INTO johns_username (id, username) VALUES('$UID','$username') ")
               or die(mysql_error());
         }

 

How can I get each username into its own row?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.