7

I have a row that needs to be deleted from a SQL table via PHP. The table has 3 columns: id, Symbol, and Shares:

foreach ($rows as $row)
{
    if($row["Symbol"] === $_POST["symbol"])
    {
     // I tried these combinations, but none of them works:
     // $sql = ("DELETE FROM stocks WHERE id = ? $_SESSION[id]");        
     // $sql = ("DELETE row FROM stocks WHERE id = $_SESSION[id]");
     // $sql = ("DELETE * FROM stocks WHERE id = $_SESSION[id]");
     // $sql = ("DELETE id, Symbol, Shares FROM stocks WHERE id = $_SESSION[id]");
      // DELETE FROM stocks WHERE id = $_SESSION["id"];
    }
}

My program enters an if statement, which I checked. The condition is fulfilled, but the DELETE is not executed. How can I fix this?

TylerH
  • 20,799
  • 66
  • 75
  • 101
user3706178
  • 125
  • 1
  • 2
  • 6

1 Answers1

14

This syntax should work in any database:

DELETE FROM stocks WHERE id = XXX

I don't know what ? $_SESSION[id] is supposed to be doing. Try without the ?:

DELETE FROM stocks WHERE id = $_SESSION[id]

That said, you should parameterize your queries rather than putting arguments into the query string.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • Then this error appears: Parse error: syntax error, unexpected 'FROM' (T_STRING) in /home/jharvard/vhosts/pset7/public/sell.php on line 23 – user3706178 Dec 07 '14 at 17:52