正如标题所示,我想将 mysql 中具有唯一引用的记录从一个表移动到另一个表。
我自己尝试了许多不同的方法以及其他成员建议的方法。
我将向您展示我想要的两页内容。一个是第一个表中的记录表。每行都有一个链接,用于将该行的数据从该表复制到另一个表。我只是无法让代码在第二页上运行以将数据复制到另一个表。
附:完成后我将检查所有代码以尝试查找 SQL 注入(inject)。
请有人尝试帮助我解决这个问题,因为它让我发疯。
感谢您提前抽出时间。
表.php
<?php
require_once('auth.php');
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name="Instruction"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM Instruction";
$result=mysql_query($sql);
?>
<style type="text/css">
body {
background-color: #FFF;
}
</style>
<p> </p>
<p> </p>
<p> </p>
<table width="1400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td width="1400"><table width="1270" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="400"><p align="center"><strong>List of Instructions</strong></p></td>
</tr>
<tr>
<td width="70" align="center"><strong>Reference</strong></td>
<td width="120" align="center"><strong>Forename</strong></td>
<td width="120" align="center"><strong>Surname</strong></td>
<td width="100" align="center"><strong>DOB</strong></td>
<td width="120" align="center"><strong>Mobile Number</strong></td>
<td width="120" align="center"><strong>Home Number</strong></td>
<td width="120" align="center"><strong>Address</strong></td>
<td width="100" align="center"><strong>Postcode</strong></td>
<td width="100" align="center"><strong>Email</strong></td>
<td width="100" align="center"><strong>Accident Date</strong></td>
<td width="120" align="center"><strong>Accident details</strong></td>
<td width="120" align="center"><strong>Refer for Triage</strong></td>
<td width="120" align="center"><strong>Refer for IA</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><? echo $rows['Reference']; ?></td>
<td><? echo $rows['Forename']; ?></td>
<td><? echo $rows['surname']; ?></td>
<td><? echo $rows['DOB']; ?></td>
<td><? echo $rows['Mobile']; ?></td>
<td><? echo $rows['Home']; ?></td>
<td><? echo $rows['Address ']; ?></td>
<td><? echo $rows['Postcode1']; ?></td>
<td><? echo $rows['Email']; ?></td>
<td><? echo $rows['Accident']; ?></td>
<td><? echo $rows['Details']; ?></td>
<td align="center"><a href="refertotriage.php?Reference=<? echo $rows['Reference']; ?>">Refer for Triage</a></td>
<td align="center"><a href="update.php?Reference=<? echo $rows['Reference']; ?>">Refer for IA</a></td>
</tr>
<?php
}
?>
</table></td>
</tr>
</table>
<p>
<?php
mysql_close();
?>
</p>
<p> </p>
逻辑/code.php
<?php
require_once('auth.php');
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name="Instruction"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
//$Reference=$_REQUEST['Reference'];
//$Forename=$_REQUEST['Forename'];
//$surname=$_REQUEST['surname'];
//$DOB=$_REQUEST['DOB'];
//$Mobile=$_REQUEST['Mobile'];
//$Home=$_REQUEST['Home'];
//$Address=$_REQUEST['Address'];
//$Postcode=$_REQUEST['Postcode1'];
//$Email=$_REQUEST['Email'];
//$Accident=$_REQUEST['Accident'];
//$Details=$_REQUEST['Details'];
//semi colon removed
// $sql="INSERT INTO
// Triage
// (
// Reference,
// Forename,
// surname,
// `D.O.B`,
// `Mobile Number`,
// `Home Number`,
// Address,
// Postcode1,
// Email,
// Accident,
// Details
// )
// VALUES
// (
// '".$Reference."',
// '".$Forename."',
// '".$surname."',
// '".$DOB."',
// '".$Mobile."',
// '".$Home."',
// '".$Address."',
// '".$Postcode1."',
// '".$Email."',
// '".$Accident."',
// '".$Details."'
// )";
// $result=mysql_query($sql);
//$sql="INSERT INTO Triage (Reference, Forename)
//SELECT Reference, Forename from `Instruction` WHERE Reference='$Reference'"
$Reference=mysql_real_escape_string($_GET['Reference']);
$sql="INSERT INTO Triage (Reference, Forename)
SELECT Reference, Forename FROM `Instruction`
WHERE Reference='$Reference' LIMIT 1";
// echo "Successful";
// echo "<BR>";
// echo "<a href='list_records.php'>View result</a>";
// mysql_error()
echo $sql;
?>
最佳答案
我自己已经解决了我遇到的问题。我并不是“获取引用资料,这样他们就不知道需要移动哪些记录。”
关于php - 将mysql中具有唯一引用的记录从一个表复制到另一个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22143212/