SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php mysql export question copy one table into a field of another.

    Hi there,

    I am wanting to backup my mysql database from one table and i want to move it into a field of another called content

    here is my code

    PHP Code:
    $query "SELECT * INTO TABLE rankbckup FROM ranks";
    echo 
    $query;
    $result mysqli_query($con,$query);
    if(!
    $result)
    {
        echo 
    "Error".mysqli_error($con);
    }
    else
    {
        echo 
    "Successfully transfer table data";

    Seems pretty simple but what i am wanting it to do is save stuff in one table empty it in the table called ranks and inserting it into a field called content in the table called rankbckup

    now the error i am getting for this problem is this

    SELECT * INTO TABLE rankbckup FROM ranksErrorYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TABLE rankbckup FROM ranks' at line 1

    can this be done or am i doing this the wrong way and also why am i getting that error above to?

    i would do it via files but it would take up too much space that is not really needed.

    any help would be good here

    Thanks,William

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    INSERT INTO rankbckup ( SELECT * FROM ranks)
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    please do a SHOW CREATE TABLE for both tables

    edit: oops, mark beat me to it (although it would be good to verify that the tables have exactly the same number of columns)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Zealot RishikeshJha's Avatar
    Join Date
    Mar 2009
    Location
    INDIA
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,

    You are getting error b'coz the syntax in not correct for sql statement. Use this sql statement

    insert into ranksbkup (select * from ranks)

    Note: The records in the first table is not deleted form the table. Only the records are copied from ranks table to rankbkup.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •