Jump to content

function giving eror


$php_mysql$

Recommended Posts

hey guys im trying to clean my strings with this function

 

///////////////////////////////////Prevents SQL injection
    function clean($str) {
		$str = @trim($str);
		if(get_magic_quotes_gpc()) {
		$str = stripslashes($str);
		/*$str = htmlspecialchars($str);*/
	}
	return mysql_real_escape_string($str);		
    }

 

my script is connected to database and inserts data in field too but using the clean function im getting this error

 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established

Link to comment
https://forums.phpfreaks.com/topic/241581-function-giving-eror/
Share on other sites

here is my include page

 

<?php
session_start();
error_reporting(E_ALL & ~E_NOTICE);	
include  'config.php';
    include  'functions/db_functions.inc.php';
    include  'functions/gn_functions.inc.php';
?>

 

my config page

 

<?php
    // Database information
    $host   = 'localhost';
    $user   = 'root';
    $password   = 'demo';
    $database   ='abcd';

?>

 

my db_functions.inc.php

 

<?php
//////////////////////database conntction////////////////
    function db_connect() {
       global $host;
       global $user;
       global $password;
       global $database;
       
        if(!$conn = mysql_connect($host, $user, $password)) {
            die("Could't connect to database server.....".mysql_error());
        } else {
            mysql_select_db($database, $conn) or die(mysql_error());
            return $conn;
        }
    }
/////////////////////////////////////SQL Execution      
    function executeSql($sql){
        $conn = db_connect();          
        $result = mysql_query($sql, $conn)
                      or die(mysql_error($conn));
        return $result;       
    }

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.