-1

Edit: Read answers below before reading my incorrect SQL knowledge lol

So I'm trying to insert a variable and for some reason it thinks it's a column, even though I have it in single quotes. What am I doing wrong? Thanks for your time.

Unknown column '$emailAddress' in 'field list'] in EXECUTE("UPDATE mailer_recipients SET email_address=$emailAddress WHERE id=539")

$sql = 'UPDATE ' . $this->recipientDbTable . ' SET ' . $this->recipientDbColumn['result_id'] . '=' . '$hash' . ' WHERE ' . $this->recipientDbColumn['id'] . '=' . $this->emailId;

    $sql = 'UPDATE ' . $this->recipientDbTable . ' SET ' . $this->recipientDbColumn['address'] . '=' . '$emailAddress' . ' WHERE ' . $this->recipientDbColumn['id'] . '=' . $this->emailId;
Alfabravo
  • 7,493
  • 6
  • 46
  • 82
Spidey
  • 45
  • 5
  • You need to understand difference between single quote and double quote, In short Single quoted strings will display things almost completely "as is. Double quote strings will display a host of escaped characters (including some regexes), and variables in the strings will be evaluated. An important point here is that you can use curly braces to isolate the name of the variable you want evaluated. Please check this http://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php – Ganesh Ghalame Aug 31 '15 at 04:19

1 Answers1

2

Try this:

$sql = "UPDATE {$this->recipientDbTable} SET {$this->recipientDbColumn['result_id']} = '{$hash}' WHERE {$this->recipientDbColumn['id']} = {$this->emailId}";

Have a read up on the difference between single and double quotes.

Matt Parlane
  • 453
  • 2
  • 11