Jump to content

[SOLVED] PHP/MySQL - DELETE works as INSERT .. Why ?


suncore

Recommended Posts

I've a very simple table ( id, url ) which contains +/- 500,000 website url's ! Now, I want to delete all websites which are for sale - again, simple preg_match against "This domain/website is for sale".

Now, when I try to delete these rows, instead of deleting, I get new rows ( and I'm not sure from where they come and how it's possible ).

 

MySQL DELETE:

mysql_query("DELETE FROM websites WHERE url='$url'");

 

What could be the reason and how to fix it ( DELETE should work as DELETE, not INSERT ) ?

Link to comment
Share on other sites

I've only 2 queries - SELECT & DELETE ( some part of useless code removed ) :

 

<?php
$sql = mysql_query("SELECT * FROM websites");
while ($data = mysql_fetch_array($sql)) {
$url = $data['url'];
$open = file_get_contents($url);
// Now, try to find "for sale" ( code removed )
if ($found = true) {	// Found - delete
	mysql_query("DELETE FROM websites WHERE url='$url'");
} else {	
	// Not found - continue
}
}
?>

Link to comment
Share on other sites

I agree with Ken2k7 and I don't think it could have been caused by that query at all. After your delete query, try exporting those values to a text file and then manually check to see if all of those are still in the database.

 

Also, use an error handler like: "or die(mysql_error())" at the ends of your queries.

Link to comment
Share on other sites

Neither one of those queries would INSERT anything.

Did you read my main post ? I wouldn't ask this "stupid" question just for fun - this is all what I have and instead of deleting something, row count increases.

If you can't help, don't say "it's not possible" - as you see, it's possible and I don't know where's the problem ( I don't use any includes - all my code goes straight into this 1 file ).

Link to comment
Share on other sites

Computers only do exactly what their code tells them to do. If you are getting rows inserted, something must be doing that. You either have a trigger setup in the database table or some script is doing it.

 

For us to help you need to supply information about what is happening in front of you. How do you know new rows are being inserted? [Edit: per your last post, you have now supplied a trickle of information about what is going on in front of you. What exactly is your code that is getting the row count? For all we know this is the highest id present and that has nothing to do with how many rows there are.]

 

Are they complete rows or is some of the information missing? If they have some information in them, what is similar about it and the rows you are deleting? What relationship is there between your page(s) that insert rows and your page(s) that delete rows? Are they the same page with a variable determining which action to perform? Is your conditional logic correct that determines which action to perform?

Link to comment
Share on other sites

Well it's *NOT* possible from the code you posted, okay? Got it?

 

Do you have a form where people can add entries to the table?

 

*NOT* is not NOT - ok ? :P

Regarding my code and forms - db contains only id, url and was populated by myself ( spider ). It has no forms, no chances to "inject" something, blah blah ..

What I want to say is, it does what I said - instead of deleting rows, row count increases. Yes, if it would be an error, it would leave them as they are, but for some reason, it does something "impossible".

I've rewritten this script to a new file and still, row count increases.

 

Finally, I found that 1,2,3 .. rows are being added again at the end of my table .. basically, first row goes to the end, second row goes to the end, etc. - how it's possible and how to stop this crap ?

Link to comment
Share on other sites

Someone got off the wrong end of the bed today. And on what world is NOT not NOT?

 

if ($found = true) {   // Found - delete

That is always true, just FYI.

 

$found is not always true - depending on preg_match result, I set it to false/true ( not found / found ).

Link to comment
Share on other sites

Sorry, 1 mistake in if statement will not change the meaning of DELETE. As I said, I wrote this in a new file ( in a rush ), so .. yeah, there might be something else I have done in the wrong way - don't judge me for these things. Questions a bit different from what you are trying to solve ???

More or less, looks like a bug or misconfiguration in my server setup ( though, I haven't changed anything "sensitive" ) - reinstalled php and now it works just fine !

 

** How to mark a thread as SOLVED ? ::)

Link to comment
Share on other sites

don't judge me for these things

 

Who's judging?  We're just trying to help and for some reason you're taking it the wrong way.  All they said was if you call a MySQL DELETE, it will delete, NEVER insert, update, select etc... which is 100% true.

 

Anyway, glad to see it's finally resolved.

Link to comment
Share on other sites

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.