View Full Version : Delete points from database
07-12-2012, 09:16 AM
I have a polygon on a web page and a delete button. The polygon is saved in the database in one table and in another table, the coordinates of polygon (latitude,longitude) are saved. When I click the delete button, the polygon in the webpage gets deleted as well as the polygon in database. However the points are not getting deleted.
I used this code:
mysqlquery("DELETE FROM polygon WHERE ID=".$GET['ID']."") or die(showsqlerrors(mysql_error()));
I also used:
mysqlquery("DELETE FROM points WHERE ID=".$GET['ID']."") or die(showsqlerrors(mysql_error()));
But it did not work.
Could anyone help me out?
07-12-2012, 12:59 PM
mysqlquery("DELETE FROM `points` WHERE `ID`=".$GET['ID']) or die(showsqlerrors(mysql_error()));
note these are not hyphens
07-12-2012, 03:35 PM
Can you be more specific than did not work? Did it throw an error?
Assuming that id is the correct fieldname, you'll want to verify that the datatype is an integer. It should match the datatype of the polygon.id. The easiest thing to do is set up these tables as innodb storage type, and apply a foreign key constraint from the points to the polygon, and add an on delete cascade to it. Then points are automatically deleted when the polygon is deleted.
The only causes for a failed deletion are either a syntactical error which will be thrown by the showsqlderrors function call, or there are no records matching the provided criteria.
One thing to note out of this, is that $GET itself is not the same as $_GET. I don't know if you are intending to use superglobal $_GET, or if you have a custom variable called $GET.
07-12-2012, 04:00 PM
It's probably because the function is mysql_query, not mysqlquery?
I'm guessing you have errors disabled, because it should have shouted that you're using a non-existant function.
07-12-2012, 04:23 PM
Yeah I was pondering that myself. Since it sounds like the first query runs, I assumed a custom function under that name was created to go with the showsqlerrors().
07-12-2012, 05:22 PM
Oh, good point, didn't think of that! If that's the case, I apologize.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.