suncore Posted May 6, 2009 Share Posted May 6, 2009 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 ) ? Quote Link to comment https://forums.phpfreaks.com/topic/157056-solved-phpmysql-delete-works-as-insert-why/ Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Well it's not from that query. Mind posting more of your code or is that it? Quote Link to comment https://forums.phpfreaks.com/topic/157056-solved-phpmysql-delete-works-as-insert-why/#findComment-827438 Share on other sites More sharing options...
suncore Posted May 6, 2009 Author Share Posted May 6, 2009 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 } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/157056-solved-phpmysql-delete-works-as-insert-why/#findComment-827461 Share on other sites More sharing options...
revraz Posted May 6, 2009 Share Posted May 6, 2009 Neither one of those queries would INSERT anything. Quote Link to comment https://forums.phpfreaks.com/topic/157056-solved-phpmysql-delete-works-as-insert-why/#findComment-827468 Share on other sites More sharing options...
Zhadus Posted May 6, 2009 Share Posted May 6, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/157056-solved-phpmysql-delete-works-as-insert-why/#findComment-827473 Share on other sites More sharing options...
suncore Posted May 6, 2009 Author Share Posted May 6, 2009 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 ). Quote Link to comment https://forums.phpfreaks.com/topic/157056-solved-phpmysql-delete-works-as-insert-why/#findComment-827475 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/157056-solved-phpmysql-delete-works-as-insert-why/#findComment-827479 Share on other sites More sharing options...
PFMaBiSmAd Posted May 6, 2009 Share Posted May 6, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/157056-solved-phpmysql-delete-works-as-insert-why/#findComment-827482 Share on other sites More sharing options...
suncore Posted May 6, 2009 Author Share Posted May 6, 2009 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 ? 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/157056-solved-phpmysql-delete-works-as-insert-why/#findComment-827487 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/157056-solved-phpmysql-delete-works-as-insert-why/#findComment-827490 Share on other sites More sharing options...
suncore Posted May 6, 2009 Author Share Posted May 6, 2009 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 ). Quote Link to comment https://forums.phpfreaks.com/topic/157056-solved-phpmysql-delete-works-as-insert-why/#findComment-827504 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Well in that if statement, it will be. Quote Link to comment https://forums.phpfreaks.com/topic/157056-solved-phpmysql-delete-works-as-insert-why/#findComment-827508 Share on other sites More sharing options...
revraz Posted May 6, 2009 Share Posted May 6, 2009 Maybe try if ($found == true) instead. Quote Link to comment https://forums.phpfreaks.com/topic/157056-solved-phpmysql-delete-works-as-insert-why/#findComment-827509 Share on other sites More sharing options...
9three Posted May 6, 2009 Share Posted May 6, 2009 You're assigning the variable $found as true. = == === Quote Link to comment https://forums.phpfreaks.com/topic/157056-solved-phpmysql-delete-works-as-insert-why/#findComment-827521 Share on other sites More sharing options...
suncore Posted May 6, 2009 Author Share Posted May 6, 2009 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/157056-solved-phpmysql-delete-works-as-insert-why/#findComment-827539 Share on other sites More sharing options...
revraz Posted May 6, 2009 Share Posted May 6, 2009 Bottom of the thread, you can change it to solved. Quote Link to comment https://forums.phpfreaks.com/topic/157056-solved-phpmysql-delete-works-as-insert-why/#findComment-827547 Share on other sites More sharing options...
Maq Posted May 6, 2009 Share Posted May 6, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/157056-solved-phpmysql-delete-works-as-insert-why/#findComment-827598 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.