Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-23-2007, 02:14 PM   PM User | #1
tanhaha_how
Regular Coder

 
Join Date: Feb 2006
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
tanhaha_how is an unknown quantity at this point
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)

Code:
<?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?????
tanhaha_how is offline   Reply With Quote
Old 02-23-2007, 05:25 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
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.
__________________
Fumigator is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:06 PM.


Advertisement
Log in to turn off these ads.