Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: insert problem

  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Thanked 0 Times in 0 Posts

    Question insert problem

    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)

    	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);
    	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?????

  2. #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Thanked 637 Times in 625 Posts
    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts