【发布时间】:2018-10-21 08:38:52
【问题描述】:
希望通过将记录从一张表移动到另一张表来存档患者。这是我尝试使用的代码:
<?php
$patient_id = $_GET['patient_id'];
include("db.php");
$sql="Select * from patient where patient_id=".$patient_id;
$result=mysqli_query($conn,$sql);
$row=mysqli_fetch_array($result);
//Call the function to archive the table
//Function definition is given below
archive_record(patient,$row);
//Once you archive, delete the record from original table
$sql = "Delete from patient where patient_id=".$patient_id;
mysqli_query($conn,$sql);
function archive_record($patient_archive,$row)
{
$sql = "insert into patient_archive values(";
$i=0;
while($i<(count($row)-1))
{
$sql.="'".$row[$i]."',";
}
$i=$i+1;
$sql.="'".$row[$i]."'";
$sql.=")";
}
?>
我在运行代码后得到这个结果 enter image description here
如何改进此代码以获得我想要的结果?
【问题讨论】:
-
首先纠正这个:
archive_record(patient,$row);- '耐心'应该是什么?$patient_archive未在函数archive_record()中使用 -
second:
$i=$i+1;在 while 之外,所以 while 将永远运行,这是您的第二个错误。 -
第三:你永远不会执行在
archive_records中创建的$sql。 -
第四:您的代码高度不安全,对 sql 注入开放。切换到准备好的语句或至少清理用户输入 (
$_GET['patient_id'])。 -
请将错误作为文本添加到问题中,而不是图像