php - escape-data mysqli function wont work -


i trying move mysql mysqli. connecting fine , simple queries seem work. however, want escape_date function , keeps tell me

notice: undefined variable: conn in $data = mysqli_real_escape_string($conn, $data);

here's code. function called when form data being processed.

ini_set('display_errors',1);  error_reporting(e_all);  // connect database $servername = "localhost"; $username = xxx; $password = xxx; $dbname = xxx;  // create connection $conn = new mysqli($servername, $username, $password, $dbname); // check connection if ($conn->connect_error) {     die("connection failed: " . $conn->connect_error); } else {     echo '<p>you connected</p>';     }   // escaping data function function escape_data($data){     //  address magic quotes     if (ini_get('magic_quotes_gpc')){         $data = stripslashes($data);     }        $data = mysqli_real_escape_string($conn, $data);     //return escaped value     return $data; } 

you got $conn within scope of escape_data(). pass argument


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -