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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOWTO insert values from one database into a different database.

Status
Not open for further replies.

bebop1065

Technical User
Dec 16, 2003
31
0
0
US
MySQL and PHP are the tools for this job.

I have a project that I am trying to complete. It is just something that I am trying to write that will make my life/work easier. The funny thing is that I could have done everything the long way and completed my task by now. I have a database of hosting customers that will grow and I'd like to give these customers access to a forum I host. If I am able to construct this script, I will setup a cron job to run it automatically.

I need to query a database and extract some values like (username, password, join date, email address, etc) from two tables in a single database. I'd then like to insert those values into a table in a different database.

The only hint I have been given is listed below. I've been playing arround with information from php.net and I am as lost as ever. I've even tried Janebuilder, but, the documentation is sparse. Can someone do my work for me? Or at least help me fill in the blanks.

I am able to connect/disconnect to the appropriate databases with no problems.



--
$hosting_info = mysql_query("SELECT * FROM customers WHERE id='1' LIMIT 1");
$hosting_row = mysql_fetch_array($hosting_info);

$hosting_username = $hosting_row["username_col"];
$hosting_password = $hosting_row["password_col"];
$hosting_email = $hosting_row["email_col"];

then, close that connection to the mysql database then open a connection to the forum database.

$forum_info = mysql_query("INSERT INTO members_table( `user_col` , `pass_col` , `email_col` ) VALUES($hosting_username, $hosting_password, $hosting_email)");

ANY and ALL help is appreciated.
SPN

CCNA student
 
Code:
$hosting_info = mysql_query("SELECT * FROM customers WHERE id='1' LIMIT 1");
 $hosting_row = mysql_fetch_array($hosting_info);

 $hosting_username = $hosting_row["username_col"];
 $hosting_password = $hosting_row["password_col"];
 $hosting_email = $hosting_row["email_col"];

The above part looks OK.

About inserting that record in another table/database,
if the columns of type varchar, text etc, u need to surround the values with the single quote.
Code:
$forum_info = mysql_query("INSERT INTO members_table( `user_col` , `pass_col` , `email_col` ) VALUES('$hosting_username','$hosting_password','$hosting_email')");

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top