Week 2 - Secure Login - Database Connection Code

/*Connects to the database */
$errmsg ="<p><br /><br /><strong>If problems continue, 
please contact the sys admin at 608-123-4567</strong></p>";

      $db_conn = mysql_connect ("MySQL.domain.com",
"auth", "auth") or
	die ($errmsg);
/*selects specified database*/
      mysql_select_db ("authdb") or
	die ($errmsg);
	
	
function cleanup_text ($value = "", $preserve = "", $allowed_tags = "") {
	if(empty($preserve)) {
		$value = strip_tags($value, $allowed_tags);
		}//end if
	$value = htmlspecialchars($value);
	return $value;
}//end cleanup_text function

//checks user input length
function string_length ($userinput, $limit) {
	$userinputlen = strlen($userinput);
	if($userinputlen > $limit) {
		die($errormsg);
		}//end if
	 		return $userinput;
	 }//end string_length

/*safe query prevents the printing out of descriptive errors.*/
function safe_query($query) {
	if(empty($query)) {
		return FALSE; 
		}//end if
	if(QUERY_DEBUG == "Off") {
		$result = mysql_query($query) or
		die($errmsg);
		}//end if
		else {
		$result = mysql_query($query) or
		die($errmsg);
			}//end else
		return $result;
	}//end safe_query