Page 1 of 2

Emergency - All records replaced

Posted: Thu Jul 27, 2006 4:15 am
by mohson
Has anyone experienced this problem,

This morning I entered the edit form of my system and edited a person record when I pressed the save button it automatically replaced all 1000 records with the edited record I had just changed. This code has worked fine for 2 years how could this suddently happen??

Any IDEAS???

Re: EMERGENCY - ALL RECORDS REPLACED

Posted: Thu Jul 27, 2006 4:17 am
by Chris Corbyn
mohson wrote:Has anyone experienced this problem,

This morning I entered the edit form of my system and edited a person record when I pressed the save button it automatically replaced all 1000 records with the edited record I had just changed. This code has worked fine for 2 years how could this suddently happen??

Any IDEAS???
Your WHERE clause probably has a bug in it. Hopefully you have a backup to restore from? :)

Posted: Thu Jul 27, 2006 4:18 am
by mohson
yeh I do have a back up. but why would my where clause suddenly have a bug when its been fine for 2 years?

Posted: Thu Jul 27, 2006 4:20 am
by Chris Corbyn
mohson wrote:yeh I do have a back up. but why would my where clause suddenly have a bug when its been fine for 2 years?
Becuase the integrity of your data has been ok for 2 years and something's now not right? Databases can seem to be working fine and dandy until you lose a bit of data integrity and then everything can go pear shaped.

Posted: Thu Jul 27, 2006 4:20 am
by mohson
Also does this mean that this problem will persist or is it just a one off problem?

Posted: Thu Jul 27, 2006 4:22 am
by mohson
Ok, so does something need to be changed or this just a randomn problem

Posted: Thu Jul 27, 2006 4:50 am
by mohson
Any answers to the above questions guys.

Posted: Thu Jul 27, 2006 4:53 am
by Benjamin
The answer is yes. (Something needs to be fixed) We would need to see the code that does the update though. Please don't bump posts, it's a big no no here.

Posted: Thu Jul 27, 2006 4:55 am
by JayBird
Please stop bumping your thread...
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:4. All users of any level are restricted to bumping (as defined here) any given thread within twenty-four (24) hours of its last post. Non-trivial posts are not considered bumping. A bump post found in violation will be deleted, and you may or may not recieve a warning. Persons bumping excessively be considered as spammers and dealt with accordingly.
...i know your issue is urgent, but people will reply if they have an answer!

Posted: Thu Jul 27, 2006 5:00 am
by mohson
Apologies for that guys, I was just panicking. Again I apologise for doing this and understand completely the logic behind it.

Ok one thing I dont understand is that this code has never changed, I also use this code for all my other edit functions and they are currently functioning correctly why is this the case?

Heres my code

Code: Select all

* Connecting, selecting database */
$link = mysql_connect("vxxxx", "xxx", "xxxx")
   or die("Could not connect : " . mysql_error());
echo "";
mysql_select_db("contact_management_system") or die("Could not select database");
	
		if(isset($_GET['person_id'])){
			$person_id=$_GET['person_id'];
		}

		if ($_POST['Submit'] == 'Save'){

			foreach ($_POST as $formName => $phpName){
				$$formName = $phpName;
			}
			
					$sql ="UPDATE people SET "
					. " salutation='"	.$salutation."'," 
					. " firstname='"	.$firstname	."'," 
					. " surname='"		.$surname."'," 
					. " organisation='" .$organisation	."'," 
					. " role='"			.$role."'," 
					. " address1='"	.	$address1."'," 
					. " address2='" .$address2."'," 
					. " city='" .$city."'," 
					. " telephone='" .$telephone."'," 
					. " mobile='" .	$mobile	."'," 
					. " fax='" .$fax."'," 
					. " dateoflastcontact='" .$dateoflastcontact."',"
					. " datecontactagain='" .$datecontactagain."',"
					. " notes='" .$notes."',"
					. " email='" .$email."',"
					. " org_id='" .	$org_id	."'";
And then you have all the form informationetc etc etc

and then you have the where clause

Code: Select all

$sql = "SELECT * FROM people WHERE person_id='" . $person_id . "'";
			//echo "<br><div align=center>" . $sql . "<br>";
			echo "<br><div align=center><br>";
			$memb = mysql_query($sql) or die(mysql_error());
			$row = mysql_fetch_array($memb);

Posted: Thu Jul 27, 2006 5:02 am
by Benjamin
What is after

Code: Select all

. " org_id='" . $org_id  ."'";
Is that the last line of $sql in your first post? That never would have worked, and would have always updated all the records. Is this the first time you have updated a record?

Posted: Thu Jul 27, 2006 5:09 am
by mohson
Oh no, Ive just looked at my other edit files and there is a "where" before the org_id

Dman I must have replaced this when I made some recent changes

Does inserting the where sound about right?

Posted: Thu Jul 27, 2006 5:10 am
by Benjamin
Yes

Posted: Thu Jul 27, 2006 5:20 am
by mohson
Thanks astions Ive now corrected this but im now getting this error message

could not insertYou have an error in your SQL syntax near 'WHERE person_id='3'' at line 1

heres the code

Code: Select all

$sql ="UPDATE people SET "
					. " salutation='"	.$salutation."'," 
					. " firstname='"	.$firstname	."'," 
					. " surname='"		.$surname."'," 
					. " organisation='" .$organisation	."'," 
					. " role='"			.$role."'," 
					. " address1='"	.	$address1."'," 
					. " address2='" .$address2."'," 
					. " city='" .$city."'," 
					. " telephone='" .$telephone."'," 
					. " mobile='" .	$mobile	."'," 
					. " fax='" .$fax."'," 
					. " dateoflastcontact='" .$dateoflastcontact."',"
					. " datecontactagain='" .$datecontactagain."',"
					. " notes='" .$notes."',"
					. " email='" .$email."',"
					. " WHERE person_id='" . $person_id."'";
Any Ideas?

Posted: Thu Jul 27, 2006 5:21 am
by jamiel
Remove the last comma after e-mail.