...

View Full Version : insert problem



tanhaha_how
02-23-2007, 02:14 PM
hi,i hav a problem here....

i hav a main page with a button to check overdue records...after i click that button,will redirect to this page and insert the overdue record to another table.but the problem is when i hav 2++ records which are overdue,then redundancy record will occur...

for eg, 1st overdue record, patientID =1
2nd overdue record, patientID =2
3rd overdue record, patientID =2(it will continue insert this record whenever i click that button)



<?php
include 'connStr.php';
include 'datediff.php';

$query = "SELECT * FROM tblpatient";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)){

$query2 = "Select * from tbloverdue";
$result2 = mysql_query($query2);
$row2 = mysql_fetch_assoc($result2);

$TD = $row["Treatment_Date"];
$patientID = $row["Patient_ID"];
$overdueID = $row2["Patient_ID"];
$diff = datediff("$TD","now","m");
if (($row["Email"]) == ""){
$row["Email"] = "NO";}

if ($diff > 5 && $patientID != $overdueID){

$query1 = "Insert into tbloverdue(Patient_ID, Name, Treatment_Date, Email)values('".$row["Patient_ID"]."', '".$row["Name"]."', '".$row["Treatment_Date"]."', '".$row["Email"]."')";
$result1 = mysql_query($query1);
}
}

mysql_query("COMMIT");

echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">";
echo "<meta http-equiv=\"REFRESH\" content=\"0; URL=overdue.php\">";

?>


can somebody pls help me?????

Fumigator
02-23-2007, 05:25 PM
You should either set up the overdue table's primary (unique) key to not allow the duplicate record, or add a query to check to see if that patient is in the table before inserting.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum