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
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;       
    }

?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.