我已經創建了一個頁面,從而MySQL查詢檢查病人是否已經存在於數據庫中,如果病人不存在,那麼下面的代碼應該將它們添加到數據庫檢查現有病人的數據庫,然後添加,如果不存在
<?php
include("includes/staffmenu.php");
include("includes/staffsession.php");
@require_once("includes/dbconfig.inc");
$firstname=$_POST["pfname"];
$middlename=$_POST["pmname"];
$surname=$_POST["psname"];
$nat=$_POST["pnat"];
$DOB=$_POST["pdob"];
$pemail=$_POST["pemail"];
$add1=$_POST["padd1"];
$add2=$_POST["padd2"];
$add3=$_POST["padd3"];
$postcode=$_POST["ppcode"];
$telephone=$_POST["pphone"];
$pcheck=mysql_query("
SELECT * FROM patient
WHERE
Patient_First_Name='$firstname' AND Patient_Middle_Name='$middlename' AND Patient_Surname='$surname' AND Patient_National_Insurance_No='$nat'
AND Patient_DOB='DOB' AND Patient_Address_Line_1='$add1' AND Patient_Address_Line_2='$add2' AND Patient_Address_Line_3='$add3' AND Patient_Postcode='$postcode'");
$myrow = mysql_fetch_row($pcheck);
if($myrow)
{ echo "This Patient already exists.<br><br> Please press the back button on your browser or the backspace button on your keyboard to go back";
}
else
{ mysql_query("INSERT INTO patient (Patient_First_Name,Patient_Middle_Name,Patient_Surname,Patient_National_Insurance_No,Patient_DOB,Patient_Email,Patient_Address_Line_1,Patient_Address_Line_2,Patient_Address_Line_3,Patient_Postcode,Patient_Phone_No )
VALUES('$firstname','$middlename','$surname','$nat','$DOB','$pemail','$add1','$add2','$add3','$postcode','$telephone')") or die (mysql_error());
echo "<br>";
echo "<p>Success! The Patient has been added to the database
</p>";
}
?>
的問題是,即使患者已經存在,它不斷增加新的......能不能有人請告知我要去的地方錯了嗎?
我希望這個代碼是附近沒有地方我 – 2013-03-17 20:29:10