0

I am trying to run a simple SELECT query inside of a PHP class, using the GET variable.

$this->Token = $_GET['Token'] ?? null;

function getRows(){   
        $query = $this->db->query("SELECT * FROM store_product_images WHERE token = ".$this->Token." ORDER BY display_order ASC");
    

When I run this, nothing shows, if I remove the WHERE it works fine

4
  • 3
    Your code is vulnerable to SQL injection attacks. Instead of building queries with string concatenation, always use prepared statements with bound parameters. See this page and this post for some good examples. Commented Apr 18, 2021 at 16:31
  • 2
    If token is a string, you would need quotes round the value,but using prepared statements solves this and a few other problems. Commented Apr 18, 2021 at 16:32
  • 2
    @NigelRen It does have quotes around it? Could you show me an example of what you mean? Commented Apr 18, 2021 at 16:32
  • 1
    You missed the quote to indicate that you passed a string on your query. You better write it like this [...] WHERE token = '{$this->Token}' ORDER BY [...]. Anyway, you should really consider to escape your value, or better to use prepared statement, as another has mentioned, your code is vulnerable to SQL injection. Commented Apr 18, 2021 at 16:38

1 Answer 1

1

you missed the quote

$query = $this->db->query("SELECT * FROM store_product_images WHERE `token`= '".$this->Token."' ORDER BY display_order ASC");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.