Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php4- multiple isert of different values

Status
Not open for further replies.

ja01

Technical User
Dec 14, 2005
48
US
Here is a snipplet of php code. I am adding user name and hash password to a table called admin

$sql = "insert into admin values ('','test1','test1',password('test83'))";

What I am doing here is inserting a last name, user id and password(hashed) into a table. The first '' is autoincremented. I have 100 dfferent (values)or names, user id and passwords to insert. How can I write this to include all 100 in the same insert statement. Will I need to write one insert statement,
Must I create a .txt file then upload? If so how would I handle the hash password?
 
Okay,I did not know you would need the database information but here it is. Don't be fooled by the password in the database connection. It just so happens that my table name is also admin
<?php
// open the connection
$conn = mysql_connect("localhost", "upsilonn_admin", "admin");

// pick the database to use
mysql_select_db("upsilonn_database1",$conn);

// create the SQL statement
$sql = "insert into admin values ('','test1','test1',password('test83'))";
 
It wasn't necessary to post the connection code -- just to say that of the myriad databases to which PHP can connect, you were using MySQL. I sincerely hope that the conneciton information you have posted in your mysql_connect() invocation is bogus.

You have a number of ways to to this.

One would be to loop through your data, generating multiple INSERT statements for each line of data.

Another would be to loop through the data, generating a single large complex insert query of the form: INSERT INTO tablename values (1, 2, 3), (2, 3, 4), (4,5,6)

Write out all the data to a CSV, then use a LOAD DATA query to insert it into the table. Then issue a UPDATE query of the form: UPDATE admin set <password column name> = password(<password column name>)

I would probably do the third.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top