The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Several inserts and delets, always one failing
Discuss Several inserts and delets, always one failing in the PHP Development forum on Dev Shed. Several inserts and delets, always one failing PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 19th, 2012, 06:51 AM
|
|
Contributing User
|
|
Join Date: Sep 2004
Location: Marbella, Spain
Posts: 383
Time spent in forums: 6 Days 8 h 41 m 34 sec
Reputation Power: 0
|
|
|
Several inserts and delets, always one failing
Hi,
I have this script to save old properties in another table then I delete from other tables, the strange is, there is always one that fails, before one of the deletes failed, I changed the way of the delete and then the last insert failed. I just dont get it.
This is what I have at this moment and the insert that does not work is the last one, being the column and tablename correct:
Code:
mysql_query($query);
$query = "INSERT INTO buscador_old SELECT * FROM buscador WHERE `id_propiedad` = '$id_propiedad'";
mysql_query($query);
$query = "INSERT INTO availability_old (id_propiedad, tipo, zona, duermen, link_ingles, link_esp, link_sve, conditions, condiciones, villkor)
SELECT id_propiedad, tipo, zona, duermen, link_ingles, link_esp, link_sve, conditions,
condiciones, villkor FROM casa WHERE `id_propiedad` = '$id_propiedad'";
mysql_query($query);
$query = "INSERT INTO Casas_alquilar_old SELECT * FROM Casas_alquilar WHERE `nombre` = '$id_propiedad'";
mysql_query($query);
$query = "INSERT INTO casa_old (id_propiedad)" .
"VALUES ('$id_propiedad')";
$sql = mysql_query ("DELETE FROM `casa` WHERE `id_propiedad` = '$id_propiedad'");
$sql = mysql_query ("DELETE FROM `buscador` WHERE `id_propiedad` = '$id_propiedad'");
$sql = mysql_query("DELETE FROM `Casas_alquilar` WHERE `nombre` = '$id_propiedad'");
Any help please, as if I do changes so the failing works, then another one fails....
|

November 19th, 2012, 09:16 AM
|
 |
SQL Consultant
|
|
Join Date: Feb 2003
Location: Toronto Canada
|
|
i'm sorry, i have never seen the error message "does not work" before

|

November 19th, 2012, 10:17 AM
|
|
|
|
>i'm sorry, i have never seen the error message "does not work" before
That's weird, because that error message shows up in this very forum alarmingly often!
;-)
|

November 19th, 2012, 10:40 AM
|
|
Contributing User
|
|
Join Date: Sep 2004
Location: Marbella, Spain
Posts: 383
Time spent in forums: 6 Days 8 h 41 m 34 sec
Reputation Power: 0
|
|
Thanks 
The thing is I have not done in phpmysql as the inserts and deletes works perfectly separately, but as I said when doing them all together there is always one that is not inserted or deleted, if I change the php to make the failing one to work then another one does not work anymore, I need to do the inserts and deletes all at the same time so must be done with php, if I do them one by one I dont have any problem at all. Therefore I dont get it.
The problem is not doing them separately, its when done all together. Dont know how to do all at the same time to test in phpmyadmin.
|

November 19th, 2012, 11:21 AM
|
 |
SQL Consultant
|
|
Join Date: Feb 2003
Location: Toronto Canada
|
|
contrary to popular belief, phpmyadmin does not run multiple sql statements
it runs them one at a time, just like you have to do, except it does them one after the other so that it only looks like it's doing multiple statements
and you still did not explain what "does not work" means

|

November 19th, 2012, 11:27 AM
|
|
Contributing User
|
|
Join Date: Sep 2004
Location: Marbella, Spain
Posts: 383
Time spent in forums: 6 Days 8 h 41 m 34 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by r937 contrary to popular belief, phpmyadmin does not run multiple sql statements
it runs them one at a time, just like you have to do, except it does them one after the other so that it only looks like it's doing multiple statements
and you still did not explain what "does not work" means
 |
Does not work, means, it does not do what it´s supposed to do, ie insert or update, I done changes many time in this code, and I always ends up with one not working, inserting or deleting depending, the way the statements are done above it´s the last insert that does not work, the one before the 3 deletes.
Thanks
So I suppose the problem is in the php handling the sql.
|

November 19th, 2012, 11:34 AM
|
 |
SQL Consultant
|
|
Join Date: Feb 2003
Location: Toronto Canada
|
|
|
okay, i'm gonna move this thread to the php forum, as php seems to be where you are having the problem
|

November 19th, 2012, 11:44 AM
|
|
Contributing User
|
|
Join Date: Sep 2004
Location: Marbella, Spain
Posts: 383
Time spent in forums: 6 Days 8 h 41 m 34 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by r937 okay, i'm gonna move this thread to the php forum, as php seems to be where you are having the problem |
Thanks did not thought about that.
|

November 19th, 2012, 01:18 PM
|
|
Registered User
|
|
Join Date: Apr 2012
Posts: 27
Time spent in forums: 3 h 38 m 44 sec
Reputation Power: 0
|
|
This should work
PHP Code:
$query = "INSERT INTO buscador_old SELECT * FROM buscador WHERE `id_propiedad` = '$id_propiedad'";
mysql_query($query);
$query = "INSERT INTO availability_old (id_propiedad, tipo, zona, duermen, link_ingles, link_esp, link_sve, conditions, condiciones, villkor)
SELECT id_propiedad, tipo, zona, duermen, link_ingles, link_esp, link_sve, conditions,
condiciones, villkor FROM casa WHERE `id_propiedad` = '$id_propiedad'";
mysql_query($query);
$query = "INSERT INTO Casas_alquilar_old SELECT * FROM Casas_alquilar WHERE `nombre` = '$id_propiedad'";
mysql_query($query);
$query = "INSERT INTO casa_old (id_propiedad)" .
"VALUES ('$id_propiedad')";
mysql_query($query);
$sql = "DELETE FROM `casa` WHERE `id_propiedad` = '$id_propiedad'";
mysql_query($sql);
$sql = "DELETE FROM `buscador` WHERE `id_propiedad` = '$id_propiedad'";
mysql_query($sql);
$sql = mysql_query("DELETE FROM `Casas_alquilar` WHERE `nombre` = '$id_propiedad'";
mysql_query($sql);
|

November 19th, 2012, 02:43 PM
|
|
Contributing User
|
|
Join Date: Sep 2004
Location: Marbella, Spain
Posts: 383
Time spent in forums: 6 Days 8 h 41 m 34 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by jpmul This should work
PHP Code:
$query = "INSERT INTO buscador_old SELECT * FROM buscador WHERE `id_propiedad` = '$id_propiedad'";
mysql_query($query);
$query = "INSERT INTO availability_old (id_propiedad, tipo, zona, duermen, link_ingles, link_esp, link_sve, conditions, condiciones, villkor)
SELECT id_propiedad, tipo, zona, duermen, link_ingles, link_esp, link_sve, conditions,
condiciones, villkor FROM casa WHERE `id_propiedad` = '$id_propiedad'";
mysql_query($query);
$query = "INSERT INTO Casas_alquilar_old SELECT * FROM Casas_alquilar WHERE `nombre` = '$id_propiedad'";
mysql_query($query);
$query = "INSERT INTO casa_old (id_propiedad)" .
"VALUES ('$id_propiedad')";
mysql_query($query);
$sql = "DELETE FROM `casa` WHERE `id_propiedad` = '$id_propiedad'";
mysql_query($sql);
$sql = "DELETE FROM `buscador` WHERE `id_propiedad` = '$id_propiedad'";
mysql_query($sql);
$sql = mysql_query("DELETE FROM `Casas_alquilar` WHERE `nombre` = '$id_propiedad'";
mysql_query($sql);
|
Puf, that worked, thousands of thanks, had many irritations with that script.
|

November 19th, 2012, 02:54 PM
|
|
|
|
Uh, you might want to look into transactions.
__________________
I ♥ ManiacDan & requinix
This is a sig, and not necessarily a comment on the OP:
Please don't be a help vampire!
|

November 19th, 2012, 03:29 PM
|
|
Contributing User
|
|
Join Date: Sep 2004
Location: Marbella, Spain
Posts: 383
Time spent in forums: 6 Days 8 h 41 m 34 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by ptr2void Uh, you might want to look into transactions. |
Yes, maybe, but that script is rarely used and only by me, but its good to know about it, thanks
|

November 19th, 2012, 04:12 PM
|
|
Registered User
|
|
Join Date: Apr 2012
Posts: 27
Time spent in forums: 3 h 38 m 44 sec
Reputation Power: 0
|
|
|
glad i could help
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|