Jump to content

New and trying to copy information from table to table...


Pyro-Tech

Recommended Posts

Hello, i am having an issue and this was one of the first places i thought to try posting.

I have a table in one database named minerva, the table called minerva_users that has the fields of username, user_password, and user_email....i want to write to a different table named accounts and with the fields name, password, email, and an additional field names state with a default of 0

what i want it to do, is copy the username to name, minerva_password to password, and minerva_email to email, and then set the state to 1....

here is my attempt at the query:

[code]SELECT username, user_password, user_email FROM `minerva_users`;
while($row = mysql_fetch_assoc($query)){
    echo $row['name'].'<br />';
    echo $row['`password`'].'<br />';
    echo $row['email'].'<br />';
    SET state='1'
}[/code]

when i enter this query, i get this error:

[code]#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'while($row = mysql_fetch_assoc($query)){
echo $row['name'].'<br />'' at line 1 [/code]

and is there a way to have it do this periodically or anything?

any help would be appreciated....i am needing a seperate table for a script im running, and don't want to cause damage to the table that this info is comming from
from your code that you posted, your query is just sitting there, not assigned as a string to a variable, or even just used as a string in a query function. Also, according to your post, the field names for minerva_users have minerva_ prefix, right? It should look something like this:

[code]
$sql = "SELECT username, user_password, user_email FROM minerva_users";
$query = mysql_query($sql);
while($row = mysql_fetch_assoc($query)){
    echo $row['minerva_name'].'<br />';
    echo $row['minerva_password'].'<br />';
    echo $row['minerva_email'].'<br />';
    SET state='1'
}
[/code]

however, you know that in phpmyadmin you can create a new table based off another table, data and all, right?
one other thing you may want to check into if you have access to run manual queries is simply to do a [url=http://dev.mysql.com/doc/refman/5.0/en/ansi-diff-select-into-table.html]SELECT INTO[/url].

hope this helps
ok...i thought the echo part is where it was writing the info it got from the first section

how do i copy the info into a new table then with different field names?


and in all honesty i don't know any MySQL so all the questions asking if i knew something...answer is prolly no  :-[

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.