1

I use mysql_real_escape_string to escape $this->piVars.

....de/index.php?searchGenre=5

$searchGenre = mysql_real_escape_string($this->piVars[searchGenre]);
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'item', 'genre = ' . $searchGenre, 'title', '');

print_r($this->piVars[searchGenre]); = string "5".

var_dump($this->piVars[searchGenre]); = string(1) "9"

print_r($searchGenre) = empty String.

var_dump($searchGenre) = bool(false).

Why?

2
  • Hard to say with so little code; what is the string you're escaping? Are you connected to a database? What do you get if you var_dump($searchGenre) instead of print_r? Commented Aug 17, 2013 at 14:12
  • You may not have a valid connection to the database...? Commented Aug 17, 2013 at 14:14

1 Answer 1

4

This is probably happening because you have no open mysql connection. you must first have an open connection for mysql_real_escape_string() to work.

mysql_connect('mysql_host', 'mysql_user', 'mysql_password') // open connection..
$searchGenre = mysql_real_escape_string($this->piVars[searchGenre]); // use it

Note: mysql_ functions are deprecated. Use prepared statements with PDO (or mysqli) instead.

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.