Frage

I'm trying to sanitize a variable and am having an issue.

This code outputs the echo correctly:

$to_raw = $_POST['to'] ;
echo $to_raw;

But this returns nothing:

$to_raw = mysql_real_escape_string($_POST['to']) ;
echo $to_raw;

Am I missing something?

War es hilfreich?

Lösung

The function mysql_real_escape_string doesn't work if you haven't called mysql_connect. Better workaround would be creating a MySQL connection on the top, before calling the mysql_real_escape_string.

mysql_connect("localhost");
$to_raw = mysql_real_escape_string($_POST['to']) ;
echo $to_raw;

Suggestion

It is better to use either PDO or mysqli_* functions compared to mysql_* functions as they are deprecated.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top