gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 01:13:15 25 4
gpt4 key购买 nike

将数据从一个表移动到另一个表时,出现查询错误:键“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.- 不要使用 mysql_* 函数,它们已被弃用,使用 mysqliPDO

2.- 您的表 testingqa1160 需要为 id 列添加 auto-increment 属性

关于php - 将数据从一个 mysql 表移动到另一个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19296777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com