Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Delete points from database

    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?

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    try:

    PHP Code:
    mysqlquery("DELETE FROM `points` WHERE `ID`=".$GET['ID']) or die(showsqlerrors(mysql_error())); 
    note these are not hyphens

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    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.

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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().

  • #6
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Oh, good point, didn't think of that! If that's the case, I apologize.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •