0

I'm literaly going crazy over this one. So I have my gamePage.php file where I can see all the info about a single videogame. The button delete invokes the following code

    if(isset($_POST['delete'])){
        $query="DELETE FROM shop.videogame WHERE IDVideogame='$id'";
        pg_query($conn, $query);
        $query="DELETE FROM shop.storage WHERE videogame='$id'";
        pg_query($conn,$query);
        echo 'Game deleted, click the "Go Back" button';            
     }

What actually happens is that only the second Delete works. The videogame is deleted from the storage table, but not from the videogame table. What's even stranger is that if I click a second time the button, the first DELETE finally works.

In other words one is supposed to click for 2 times the same button for no reason.

user2959229
  • 1,360
  • 2
  • 11
  • 21
someCoder
  • 185
  • 3
  • 15
  • 1
    Are you getting any errors? You should have error reporting turned on. – Andrius Nov 26 '15 at 10:09
  • do you have integrity constraints in either table ? – Calimero Nov 26 '15 at 10:13
  • 1
    Please, [confirm that this is not your issue](http://stackoverflow.com/a/21798517/4903925) (case sensitive in unquotted SQL operation)... finally, add a vardump to the result of each operation an log it, then post on your question – Bonatti Nov 26 '15 at 10:28

1 Answers1

3

I guess shop.storage.videogame is a ForeignKey to shop.videogame.IDVideogame.

If I have right, then switch delete statements.

$query="DELETE FROM shop.storage WHERE videogame='$id'";
pg_query($conn, $query);
$query="DELETE FROM shop.videogame WHERE IDVideogame='$id'";
pg_query($conn, $query);
Tomasz Jakub Rup
  • 10,502
  • 7
  • 48
  • 49