2014-03-03 35 views
0

我想从一张表到另一张表中移动一条带mysql中唯一引用的记录。从一张表到另一张表在mysql中复制一条带有唯一引用的记录

我已经尝试了许多不同的方法,我自己和其他成员建议。

我会告诉你我的两页我想上班。一个是来自第一个表的记录表。它在每一行上都有一个链接,将该行的数据从该表复制到另一个表。我只是不能让代码在第二页上工作,将数据复制到另一个表中。

p.s.我会在完成所有代码后尝试查找SQL注入。

请有人试试,帮助我解决这个问题,因为它让我疯狂。

感谢您的时间提前。

Table.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>&nbsp;</p> 
<p>&nbsp;</p> 
<p>&nbsp;</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>&nbsp;</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; 

?> 
+1

附注,'mysql_ *'已被弃用;使用[MySQLi](http://www.php.net/manual/en/book.mysqli.php)或[PDO](http://www.php.net/manual/en/book.pdo.php)和变量绑定技术,而不是转义数据并将数据填充到查询中。 – Passerby

+1

move = INSERT ... SELECT,然后是DELETE - 您可以将此作为交易 – Strawberry

+0

用于提醒路人和草莓,我想我已经解决了我自己遇到的问题。我希望'获取参考资料,以便他们不知道需要移动的记录。谢谢 – user3301611

回答

0

我有固定自己,我遇到的问题。我希望'获取参考资料,以便他们不知道需要移动的记录。

相关问题