Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/165126-solved-whats-wrong-with-this-query/
Share on other sites

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);
?>

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);

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..

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)

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

$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.

$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());
?>

 

 

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 ).

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();

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());
?>

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.

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.

 

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.

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());
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.