mysql_real_escape_string

From: Date: Mon, 04 Aug 2003 01:58:23 +0000
Subject: mysql_real_escape_string
Groups: php.general 
Request: Send a blank email to php-general+get-158108@lists.php.net to get a copy of this message
The following function is from Larry Ullman's PHP and mySQL on page 217 - script 6.8 - in which there is a connection to a mySQL database using PHP. My question is that I'm not sure of the global variable $dbc. If I am to understand...this made up function escape_data() will receive a piece of data - say $_POST['first_name'] - and then check if magic_quotes_gpc is turned on in the ini file. If it returned true, then stripslashes will be applied to the data - if it is not turned on, then slashes will be applied to the data variable. What is the reason that the global variable $dbc is declared in the function - I cannot find another instance of $dbc outside of the function in script 6.8. Thank you, Tony Ritter ..................... function escape_data($data) { global $dbc; if (ini_get('magic_quotes_gpc')) { $data=stripslashes($data); } return mysql_real_escape_string($data,$dbc); } ............................. //check for a first name if(empty($_POST['first_name'])) { $fn=FALSE; $message='<p>You forgot to enter you first name</p>'; } else { $fn= escape_data($_POST['first_name']); // calling the function } ..............

« previous php.general (#158108) next »