gangsterwanster1 Posted July 8, 2009 Share Posted July 8, 2009 mysql_query("delete bad_rows.* from account as good_rows inner join account as bad_rows on bad_rows.username = good_rows.username and bad_rows.id > good_rows.id)", $connect); How come the query works when i enter it in phpmyadmin, to delete duplicates yet when i add it in the php code nothing happens? Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/ Share on other sites More sharing options...
haku Posted July 8, 2009 Share Posted July 8, 2009 Are you sure $connect holds a valid connection? Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-870705 Share on other sites More sharing options...
gangsterwanster1 Posted July 8, 2009 Author Share Posted July 8, 2009 Are you sure $connect holds a valid connection? $connect = mysql_connect("127.0.0.1", "root", "") mysql_select_db("MainDB", $connect) Its correct, but for some reason it doesn't work lol. Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-870710 Share on other sites More sharing options...
gangsterwanster1 Posted July 8, 2009 Author Share Posted July 8, 2009 I was thinking it was where i put it in my script but thats not the case. i made a blank php file and it wasnt able to delete the duplicates... <?php $connect = mysql_connect("127.0.0.1", "root", "") mysql_select_db("MainDB", $connect) mysql_query("delete bad_rows.* from account as good_rows inner join account as bad_rows on bad_rows.username = good_rows.username and bad_rows.id > good_rows.id)", $connect); mysql_close($connect); ?> Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-870758 Share on other sites More sharing options...
gangsterwanster1 Posted July 8, 2009 Author Share Posted July 8, 2009 any idea? Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-870968 Share on other sites More sharing options...
trq Posted July 8, 2009 Share Posted July 8, 2009 You can't use a JOIN within a DELETE statement. Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-870969 Share on other sites More sharing options...
trq Posted July 8, 2009 Share Posted July 8, 2009 Oops, apparently you can. http://dev.mysql.com/doc/refman/5.0/en/delete.html Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-870972 Share on other sites More sharing options...
Zane Posted July 8, 2009 Share Posted July 8, 2009 you don't have any semicolons $connect = mysql_connect("127.0.0.1", "root", "") // ; mysql_select_db("MainDB", $connect) // ; also...you need to assign mysql_query to a variable like so $query = mysql_query("delete bad_rows.* from account as good_rows inner join account as bad_rows on bad_rows.username = good_rows.username and bad_rows.id > good_rows.id)", $connect); mysql_close($connect); Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-870975 Share on other sites More sharing options...
gangsterwanster1 Posted July 8, 2009 Author Share Posted July 8, 2009 you don't have any semicolons $connect = mysql_connect("127.0.0.1", "root", "") // ; <-- here mysql_select_db("MainDB", $connect) // ; <-- and here also...you need to assign mysql_query to a variable like so $query = mysql_query("delete bad_rows.* from account as good_rows inner join account as bad_rows on bad_rows.username = good_rows.username and bad_rows.id > good_rows.id)", $connect); mysql_close($connect); Ok i did the changes and still nothing happens lol.. Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-871155 Share on other sites More sharing options...
Zane Posted July 8, 2009 Share Posted July 8, 2009 by nothing you mean....?.... - it does literally nothing at all - the program doesn't execute without an error - NOTHING is deleted from the database. - NOTHING is displayed on the screen - sounds don't chime and jingle along with fireworks when you run the code. - so...what DOES happen...because the code seems to be fine...especially since the query works in phpmyadmin (if that's true) Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-871164 Share on other sites More sharing options...
gangsterwanster1 Posted July 8, 2009 Author Share Posted July 8, 2009 by nothing you mean....?.... - it does literally nothing at all: - the program doesn't execute without an error - NOTHING is deleted from the database. - NOTHING is displayed on the screen - sounds don't chime and jingle along with fireworks when you run the code. - so...what DOES happen...because the code seems to be fine...especially since the query works in phpmyadmin (if that's true) - it does literally nothing at all: blank page - the program doesn't execute without an error: no error - NOTHING is deleted from the database.: nothing is deleted - NOTHING is displayed on the screen: yep - sounds don't chime and jingle along with fireworks when you run the code.: lol Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-871199 Share on other sites More sharing options...
gangsterwanster1 Posted July 9, 2009 Author Share Posted July 9, 2009 Been waiting all day for a reason? Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-871636 Share on other sites More sharing options...
haku Posted July 9, 2009 Share Posted July 9, 2009 $query = mysql_query("delete bad_rows.* from account as good_rows inner join account as bad_rows on bad_rows.username = good_rows.username and bad_rows.id > good_rows.id)", $connect) or die(mysql_error()); mysql_close($connect) or die(mysql_error()); This will at least tell you what the problem is. Easier to fix then. Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-871777 Share on other sites More sharing options...
gangsterwanster1 Posted July 10, 2009 Author Share Posted July 10, 2009 $query = mysql_query("delete bad_rows.* from account as good_rows inner join account as bad_rows on bad_rows.username = good_rows.username and bad_rows.id > good_rows.id)", $connect) or die(mysql_error()); mysql_close($connect) or die(mysql_error()); This will at least tell you what the problem is. Easier to fix then. Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 4 -Using the latest version of XAMPP so i can test it locally before i put it on the net. Full code <?php $connect = mysql_connect("127.0.0.1", "root", "") or die('Cant connect'); mysql_select_db("MainDB", $connect) or die('Cant select database'); $query = mysql_query("delete bad_rows.* from account as good_rows inner join account as bad_rows on bad_rows.username = good_rows.username and bad_rows.id > good_rows.id)", $connect) or die(mysql_error()); mysql_close($connect) or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-872427 Share on other sites More sharing options...
corbin Posted July 10, 2009 Share Posted July 10, 2009 delete bad_rows.* from account as good_rows inner join account as bad_rows on bad_rows.username = good_rows.username and bad_rows.id > good_rows.id) You have a trailing ). Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-872434 Share on other sites More sharing options...
gangsterwanster1 Posted July 10, 2009 Author Share Posted July 10, 2009 delete bad_rows.* from account as good_rows inner join account as bad_rows on bad_rows.username = good_rows.username and bad_rows.id > good_rows.id) You have a trailing ). My bad i missed that, but now i get this; Parse error: parse error in C:\xampp\htdocs\Project\test.php on line 7 Line 7 is bad_rows.id > good_rows.id)", $connect) or die(mysql_error(); Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-872441 Share on other sites More sharing options...
haku Posted July 10, 2009 Share Posted July 10, 2009 Then you made a mistake somewhere (deleted the wrong bracket maybe?) because removing the bracket from inside the quotes wouldn't have caused that error. Lets see your current code. Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-872442 Share on other sites More sharing options...
gangsterwanster1 Posted July 10, 2009 Author Share Posted July 10, 2009 Then you made a mistake somewhere (deleted the wrong bracket maybe?) because removing the bracket from inside the quotes wouldn't have caused that error. Lets see your current code. <?php $connect = mysql_connect("127.0.0.1", "root", "") or die('Could not connect'); mysql_select_db("MainDB", $connect) or die('Could not select database'); $query = mysql_query("delete bad_rows.* from account as good_rows inner join account as bad_rows on bad_rows.username = good_rows.username and bad_rows.id > good_rows.id)", $connect) or die(mysql_error(); mysql_close($connect) or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-872453 Share on other sites More sharing options...
corbin Posted July 10, 2009 Share Posted July 10, 2009 bad_rows.id > good_rows.id)", $connect) or die(mysql_error() You removed the wrong ) entirely... Try bad_rows.id > good_rows.id", $connect) or die(mysql_error()) Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-872467 Share on other sites More sharing options...
xtopolis Posted July 10, 2009 Share Posted July 10, 2009 I think you're missing a ( to surround the ON condition. $query = mysql_query("DELETE bad_rows.* FROM account AS 'good_rows' INNER JOIN account AS 'bad_rows' ON (bad_rows.username = good_rows.username AND bad_rows.id > good_rows.id)", $connect) or die(mysql_error()); (Line4) , I modified your statement so it could be more easily read. Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-872468 Share on other sites More sharing options...
gangsterwanster1 Posted July 10, 2009 Author Share Posted July 10, 2009 bad_rows.id > good_rows.id)", $connect) or die(mysql_error() You removed the wrong ) entirely... Try bad_rows.id > good_rows.id", $connect) or die(mysql_error()) I get this error now; Parse error: parse error in C:\xampp\htdocs\Project\test.php on line 8 I think you're missing a ( to surround the ON condition. $query = mysql_query("DELETE bad_rows.* FROM account AS 'good_rows' INNER JOIN account AS 'bad_rows' ON (bad_rows.username = good_rows.username AND bad_rows.id > good_rows.id)", $connect) or die(mysql_error()); (Line4) , I modified your statement so it could be more easily read. With your code i get this; You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''good_rows' INNER JOIN account AS 'bad_rows' ' at line 2 This is so annoying, it works in phpadmin yet i am having all these troubles using it in php. Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-872484 Share on other sites More sharing options...
corbin Posted July 10, 2009 Share Posted July 10, 2009 I didn't see the ON clause, so you actually needed the parentheses I removed. What's your current code? Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-872485 Share on other sites More sharing options...
xtopolis Posted July 10, 2009 Share Posted July 10, 2009 edit - im confusing myself, post current code. Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-872494 Share on other sites More sharing options...
gangsterwanster1 Posted July 10, 2009 Author Share Posted July 10, 2009 I didn't see the ON clause, so you actually needed the parentheses I removed. What's your current code? Well then i am back to this. <?php $connect = mysql_connect("127.0.0.1", "root", "") or die('Could not connect'); mysql_select_db("MainDB", $connect) or die('Could not select database'); $query = mysql_query("delete bad_rows.* from account as good_rows inner join account as bad_rows on bad_rows.username = good_rows.username and bad_rows.id > good_rows.id)", $connect) or die(mysql_error(); mysql_close($connect) or die(mysql_error()); ?> Do you have a database with duplicates where you can try the code out? edit - im confusing myself, post current code. Same code as before, all i changed was $query = mysql_query("DELETE bad_rows.* FROM account AS 'good_rows' INNER JOIN account AS 'bad_rows' ON (bad_rows.username = good_rows.username AND bad_rows.id > good_rows.id)", $connect) or die(mysql_error()); But then once i got the error i changed it back to what it was earlier. Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-872509 Share on other sites More sharing options...
corbin Posted July 10, 2009 Share Posted July 10, 2009 Missing a ). This should work . <?php $connect = mysql_connect("127.0.0.1", "root", "") or die('Could not connect'); mysql_select_db("MainDB", $connect) or die('Could not select database'); $query = mysql_query("delete bad_rows.* from account as good_rows inner join account as bad_rows on bad_rows.username = good_rows.username and bad_rows.id > good_rows.id)", $connect) or die(mysql_error()); mysql_close($connect) or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/#findComment-872513 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.