-1

我正在尝试同时删除患者记录和与其患者 ID 相关的任何约会,但两者都不起作用,有人可以告诉我哪里出错了吗?

我的代码是:

<?php
include("includes/staffmenu.php");
include("includes/staffsession.php");
@require_once("includes/dbconfig.inc");

$patid = $_GET['patid'];

$patientname = mysql_query("SELECT * From patient WHERE Patient_ID=$patid");
    while($row = mysql_fetch_array($patientname))
        {   $pfname=$row['Patient_First_Name'];
            $pmname=$row['Patient_Middle_Name'];
            $psname=$row['Patient_Surname'];
        }

  echo "<h1>Success $pfname $pmname $psname (Patient ID: $patid) has been removed from our database, along with any appointments in their name</h1>";

    mysql_query("DELETE FROM appointment, patient 
    USING patient INNER JOIN appointment ON (patient.Patient_ID = appointment.Patient_ID) 
    WHERE patient.Patient_ID='$patid'");

  ?>

它肯定会得到患者 ID,因为患者 ID 的名称呼应得很好......

4

1 回答 1

1
DELETE patients, appointments FROM patients
LEFT JOIN appointments USING(Patient_ID)
WHERE Patient_ID = 1

参考http://dev.mysql.com/doc/refman/5.5/en/delete.html

附言。考虑使用参数来传递 patid,因为您正在使用直接来自 GET 的值打开自己的 sql 注入

http://php.net/manual/en/mysqli-stmt.bind-param.php

pps。你也应该把回声放在最后,因为你当时还没有真正删除:)

于 2013-03-17T18:52:11.637 回答