Jump to content

[SOLVED] mysql_real_escape_string problem


AdRock

Recommended Posts

I have been rewriting my website and I have got a problem with validating user input.

 

I am trying to check against sql injection using mysql_real_escape_string which i have done before but it's not working properly now

 

The errors i am getting are these:

Access denied for user: 'ODBC@localhost' (Using password: NO) in d:\\Apache\\htdocs\\copy of working\\php\\functions.php on line 262

PHP Warning:  mysql_real_escape_string()  Access denied for user: 'ODBC@localhost' (Using password: NO) in d:\\Apache\\htdocs\\copy of working\\php\\functions.php on line 262

PHP Warning:  mysql_real_escape_string()  A link to the server could not be established in d:\\Apache\\htdocs\\copy of working\\php\\functions.php on line 262

 

Here is the function is question

// Function to check user input on the form such as prevent sql injection

function check_input($value)
{
    // Stripslashes
    if (get_magic_quotes_gpc()){
	$value = stripslashes($value);
    }
    // Quote if not a number
    if (!is_numeric($value)){
	$value = mysql_real_escape_string($value);
    }
    return $value;
}

 

There is a connection to the database becuase i call the database functions at the top of the page

 

This is the top part of the page which checks user input

<?php
require_once('php/database/MySQL.php');
require_once('php/database/connection.php');
require_once('php/init.php');
    /**
    * forgotpassword.php is the the page that takes validated values from a form, passing them
    * to the forgot_password function, to create a new password and email it to the user.
    */
    // The title of the page
    $title = "Forgotten Password Recovery";

    // Include the validation classes
    require_once('php/validators/ValidateEmail.php');
    require_once('php/validators/ValidateCaptcha.php');

$useremail ="";

    // Validate the form
    if ( isset ($_POST['recover']) ) {


    	//variables for checking the user's email
    	$email = check_input(trim(strtolower($_POST['email'])));

Any ideas why it's doing this?

 

Link to comment
https://forums.phpfreaks.com/topic/120107-solved-mysql_real_escape_string-problem/
Share on other sites

db connection resource is not available within a function. Add

global $mysql;  //or whatever your dbconnection is called

as the first line in function.

 

You do not need to specify a connection, the last open connection is used by default.

 

Your connection appears to be failing. Id start debuging there first.

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.