Jump to content

Recommended Posts

I posted this in sql forum but there is no one in there!

 

Hi I have a very long list for example john, david, james, john.

 

I want to add these names into my table which containts user_id, name, password

 

Obviously I want these in the name field. How would I do this?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/51505-insert-long-list-into-phpmyadmin-table/
Share on other sites

<?php

$name = array("john", "david", "james", "linda");
$password = "??";

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

   mysql_query("INSERT INTO table (name, password) VALUES ('$name[$i]', '$password')");

}

?>

 

I'm not sure if you already have the values of user_id and password already filled in for these people, or if you are trying to add all completely new rows? This code adds all completely new rows.

Well, if you have all these names in a text file there is a way to pull them all out using fopen() and then putting them all into an array....but I don't have time to put the script together for you. There are plenty of tutorials out there that explain how to do this though, just google it and I am sure you will find something. Maybe someone else can help you =]

 

You might want to give an example of what your text file looks like. Like are the names separated by commas, spaces, or what? Just copy and paste like 5 names from the file to show us how you set it up.

 

I will be back on later if you still need the help, I am sure someone will come along and help you though ^^

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.