Jump to content

Logical Database Query Question?


Solarpitch

Recommended Posts

Hey Guys,

 

I currently have 2 tables in my database. One called "members" and another called "phpbb_users" (which is the user's table in my forum)

 

Basically I want to get all the results from my members tables and then automatically insert the values into the phpbb_users table.

 

I have the following code below which I am trying but doesn't work. Can anyone offer a little support on this?

 

$mysql_connect = new mysqli("localhost", "xxxxx", "xxxxx");
$mysql_connect->select_db('xxxxx');


$query1  = ("SELECT * FROM members");
$result1= mysqli_query($mysql_connect, $query1);

while($row = $result1->fetch_assoc())

{

****** This code just returns the next user id value in phpbb_users.

$query = ("SELECT MAX(user_id) `user_id` FROM `phpbb_users`");
$result = mysqli_query($mysql_connect, $query);


$row = $result->fetch_assoc();

$get_val = $row['user_id'];
$get_val++;

******


$sql = 

"INSERT INTO phpbb_users (user_id, username, user_password, user_regdate, user_email) VALUES ('$get_val',".  $row['username']  .",".  $row['user_password']  .",".time().",".  $row['email']  .")";

mysqli_query($mysql_connect, $sql);

}

Link to comment
https://forums.phpfreaks.com/topic/57887-logical-database-query-question/
Share on other sites

if the user_id column in phpbb_users table is defined as auto_increment, you can

 

INSERT INTO phpbb_users (username, user_password, user_regdate, user_email)
SELECT username, user_password, NOW(), email FROM members 

See I have all that working fine. Its just now that I have created a forum, I want to copy all my existing users from my "members" table and insert them into the "phpbb_users" table rather thank having to do this for every single record in the database I want to do it in one go.

 

 

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.