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
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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  :-[
Link to comment
Share on other sites

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.