Emergency - All records replaced

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Emergency - All records replaced

Post 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???
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: EMERGENCY - ALL RECORDS REPLACED

Post 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? :)
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post 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?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

Also does this mean that this problem will persist or is it just a one off problem?
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

Ok, so does something need to be changed or this just a randomn problem
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

Any answers to the above questions guys.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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!
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post 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);
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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?
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post 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?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Yes
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post 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?
jamiel
Forum Contributor
Posts: 276
Joined: Wed Feb 22, 2006 5:17 am
Location: London, United Kingdom

Post by jamiel »

Remove the last comma after e-mail.
Post Reply