将数据从一个mysql表移动到另一个mysql表

时间:2013-10-10 13:14:12

标签: php mysql

当将数据从表移动到另一个时,我在查询中得到错误:对于'PRIMARY'键重复输入'0' 我不在乎复制主键我希望每个表都有自己的主键 - 这个表只保存要处理,检查和发布的数据,然后将它们移动到包含所有处理数据的最终表。                           

    <basefont face="Arial">
    <title>QA-1160 Search</title>
    </head>

    <body>
          <?php

    // include the page Header

    include('header.php');

    ?>

    <?php

    //retrieve session data
    echo $_SESSION['mnumber'];
    echo "<P>";
    $mnumber=$_SESSION['mnumber'];
    $amnumber=$mnumber;  
    $mnumber=" '".$mnumber."' ";

    // set database server access variables:

    $host = "localhost";

    $user = "test";

    $pass = "test";

    $db = "test";

    // open connection

    $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

    // select database

    mysql_select_db($db) or die ("Unable to select database :)!");

    // create query

    $query = "insert into testingqa1160 (material, test, sample, frequency, stp,    rtr, notes, usl,    lsl) SELECT material, test, sample, frequency,  stp,    rtr, notes, usl,    lsl FROM qa1160 WHERE material=";
    $query=$query.$mnumber;
    // execute query

    $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());


    // mysql_free_result($result);

    // close connection

    mysql_close($connection);
    // clear session
    session_unset();
    session_destroy();
    // load test data

    // open connection

    $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

    // select database

    mysql_select_db($db) or die ("Unable to select database :)!");

    // create query


    $query = "SELECT * FROM testingqa1160";
    // $query=$query.$mnumber;
    // execute query

    $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

    // see if any rows were returned

    if (mysql_num_rows($result) > 0) {

        // yes

        // print them one after another

        echo "<center><table cellpadding=5 border=1>";
           echo "<tr>";
            echo "<center>";
            echo "<td>"."ID"."</td>";
            echo "<td>"."Material"."</td>";
            echo "<td>"."Test"."</td>";
            echo "<td>"."Sample"."</td>";
            echo "<td>"."Frequency"."</td>";
            echo "<td>"."STP"."</td>";
            echo "<td>"."Release"."</td>";
            echo "<td>"."Notes"."</td>";
            echo "<td>"."LSL"."</td>";
            echo "<td>"."USL"."</td>";
            echo "</center></tr>";

        while($row = mysql_fetch_row($result)) {

            echo "<tr>";

            echo "<td>".$row[0]."</td>";
            echo "<td>".$row[1]."</td>";
            echo "<td>".$row[2]."</td>";
            echo "<td>".$row[3]."</td>";
            echo "<td>".$row[4]."</td>";
            echo "<td>".$row[5]."</td>";
            echo "<td>".$row[6]."</td>";
            echo "<td>".$row[7]."</td>";
            echo "<td>".$row[9]."</td>";
            echo "<td>".$row[8]."</td>";
            echo "</tr>";

        }

        echo "</table></center>";


    echo "</center>";
    }

    else {

        // no

        // print status message
    echo "<center><FONT SIZE=18>";
    echo $_GET["mnumber"];
        echo "   Materail is not found! </font>";
        echo "</center>";

    }

    // free result set memory

    mysql_free_result($result);

    // close connection

    mysql_close($connection);
    ?>
    <td><a href="/reviewtesting.php">Testing</a></td>
          <?php

    // include the page footer

    include('footer.php');

    ?>
    </body>

    </html>

1 个答案:

答案 0 :(得分:0)

1.-不要使用 mysql _ * 函数,不推荐使用它们,使用mysqliPDO

2.-您的表格testingqa1160需要auto-increment列的id属性