4

If I execute my PHP code:

$serName = $_GET['username'];
// Code for sanitation here
// [...]
$sql = "SELECT NAME FROM PLAYERS WHERE NAME LIKE '%$serName%'"; 

I get division error, how do I use a variable in a query with wildcards on both sides?

2
  • 1
    You must sanitize your GET string before putting it at your query.. Commented Apr 7, 2013 at 16:12
  • @Svetlio Yes I have sanatized it, I have just left it like that so people won't be confused my my functions. Commented Apr 7, 2013 at 16:15

2 Answers 2

3

right query

SELECT NAME FROM PLAYERS WHERE NAME LIKE '%{$serName}%'

And you should use prepared statements

Sign up to request clarification or add additional context in comments.

2 Comments

Why cannot he use PDO if he feels like it? (;
He certainly can :) I advised for prepared statements, not against PDO.
0
$sql = "SELECT NAME FROM PLAYERS WHERE NAME LIKE '%" .$serName. "%'"; 

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.